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

40 lines, 22 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 it.Next()
21
22 self.assertEqual('b', it.FirstValue().s)
23 it.Next()
24
25 self.assertEqual(None, it.FirstValue())
26
27 mylist = value.List([value.Str('x'), value.Str('y')])
28
29 it = val_ops.ListIterator(mylist)
30 self.assertEqual('x', it.FirstValue().s)
31 x = it.Next()
32
33 self.assertEqual('y', it.FirstValue().s)
34 x = it.Next()
35
36 self.assertEqual(None, it.FirstValue())
37
38
39if __name__ == '__main__':
40 unittest.main()