OILS / ysh / val_ops_test.py View on Github | oilshell.org

44 lines, 26 significant
1#!/usr/bin/env python2
2"""
3val_ops_test.py: Tests for val_ops.py
4"""
5from __future__ import print_function
6
7import unittest
8
9from _devbuild.gen.value_asdl import value
10from ysh import val_ops # module under test
11
12
13class 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
43if __name__ == '__main__':
44 unittest.main()