| 1 | #!/usr/bin/env python2
 | 
| 2 | from __future__ import print_function
 | 
| 3 | 
 | 
| 4 | import unittest
 | 
| 5 | 
 | 
| 6 | from builtin import read_osh  # module under test
 | 
| 7 | from osh import split
 | 
| 8 | 
 | 
| 9 | 
 | 
| 10 | class BuiltinTest(unittest.TestCase):
 | 
| 11 | 
 | 
| 12 |     def testAppendParts(self):
 | 
| 13 |         # allow_escape is True by default, but False when the user passes -r.
 | 
| 14 |         CASES = [
 | 
| 15 |             (['Aa', 'b', ' a b'], 100, 'Aa b \\ a\\ b'),
 | 
| 16 |             (['a', 'b', 'c'], 3, 'a b c '),
 | 
| 17 |         ]
 | 
| 18 | 
 | 
| 19 |         for expected_parts, max_results, line in CASES:
 | 
| 20 |             sp = split.IfsSplitter(split.DEFAULT_IFS, '')
 | 
| 21 |             spans = sp.Split(line, True)
 | 
| 22 |             print('--- %r' % line)
 | 
| 23 |             for span in spans:
 | 
| 24 |                 print('  %s %s' % span)
 | 
| 25 | 
 | 
| 26 |             parts = []
 | 
| 27 |             read_osh._AppendParts(line, spans, max_results, False, parts)
 | 
| 28 |             strs = [buf.getvalue() for buf in parts]
 | 
| 29 |             self.assertEqual(expected_parts, strs)
 | 
| 30 | 
 | 
| 31 |             print('---')
 | 
| 32 | 
 | 
| 33 | 
 | 
| 34 | if __name__ == '__main__':
 | 
| 35 |     unittest.main()
 |