# Copyright 2006-2007 Grant T. Olson.
# See LICENSE for terms.
import unittest
from util import eval_code, eval_raises_code

class test_opcodes_tuples(unittest.TestCase):

    def test_tuple_unpack(self):
        self.failUnless(eval_code("a,b=99,100","",title='test_opcodes_tuples: 1'))
        self.failUnless(eval_code("a,b,c=1,2,3;(a,b,c)","(1, 2, 3)\n",title='test_opcodes_tuples: 2'))

        #lists should unpack too
        self.failUnless(eval_code("[a,b,c,d,e] = (1,2,3,4,5);(a,c,e)","(1, 3, 5)\n",title='test_opcodes_tuples: 3'))
        self.failUnless(eval_code("[a,b,c,d,e] = [1,2,3,4,5];(a,c,e)","(1, 3, 5)\n",title='test_opcodes_tuples: 3'))

        # and so should iterators
        self.failUnless(eval_code("[a,b,c,d,e] = range(1, 6);(a,b,d)","(1, 2, 4)\n",title='test_opcodes_tuples: 4'))

    def test_bad_counts(self):
        self.failUnlessRaises(IndexError,eval_raises_code,"a,b,c=99,100",'single','test_opcodes_tuples: 1')
        #self.failUnlessRaises(ValueError,eval_raises_code,"a,b=99,100,101",'single','test_opcodes_tuples: 1')

if __name__ == "__main__":
    unittest.main()
