| 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.value_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 | mylist = value.List([value.Str('x'), value.Str('y')])
|
| 30 |
|
| 31 | it = val_ops.ListIterator(mylist)
|
| 32 | self.assertEqual('x', it.FirstValue().s)
|
| 33 | self.assert_(not it.Done())
|
| 34 | x = it.Next()
|
| 35 |
|
| 36 | self.assertEqual('y', it.FirstValue().s)
|
| 37 | self.assert_(not it.Done())
|
| 38 | x = it.Next()
|
| 39 |
|
| 40 | self.assert_(it.Done())
|
| 41 |
|
| 42 |
|
| 43 | if __name__ == '__main__':
|
| 44 | unittest.main()
|