1 #!/usr/bin/env python2
2 """
3 val_ops_test.py: Tests for val_ops.py
4 """
5 from __future__ import print_function
6
7 import unittest
8
9 from _devbuild.gen.runtime_asdl import value
10 from ysh import val_ops # module under test
11
12
13 class IteratorTest(unittest.TestCase):
14
15 def testIterator(self):
16 a = ['a', 'b']
17
18 it = val_ops.ArrayIter(a)
19 self.assertEqual('a', it.FirstValue().s)
20 self.assert_(not it.Done())
21 it.Next()
22
23 self.assertEqual('b', it.FirstValue().s)
24 self.assert_(not it.Done())
25 it.Next()
26
27 self.assert_(it.Done())
28
29
30 mylist = value.List([value.Str('x'), value.Str('y')])
31
32 it = val_ops.ListIterator(mylist)
33 self.assertEqual('x', it.FirstValue().s)
34 self.assert_(not it.Done())
35 x = it.Next()
36
37 self.assertEqual('y', it.FirstValue().s)
38 self.assert_(not it.Done())
39 x = it.Next()
40
41 self.assert_(it.Done())
42
43
44 if __name__ == '__main__':
45 unittest.main()