OILS / mycpp / format_strings_test.py View on Github | oilshell.org

43 lines, 25 significant
1#!/usr/bin/env python3
2"""
3format_strings_test.py: Tests for format_strings.py
4"""
5from __future__ import print_function
6
7import unittest
8
9import format_strings # module under test
10
11
12class FormatStringsTest(unittest.TestCase):
13
14 def testParse(self):
15 parts = format_strings.Parse('foo [%s]')
16 self.assertEqual(3, len(parts))
17 print(parts)
18
19 # literal %
20 parts = format_strings.Parse('%d%%')
21 self.assertEqual(2, len(parts))
22 print(parts)
23
24 parts = format_strings.Parse('%s %d %s')
25 self.assertEqual(5, len(parts))
26 print(parts)
27
28 parts = format_strings.Parse('%s\t%s\n')
29 self.assertEqual(4, len(parts))
30 print(parts)
31
32 parts = format_strings.Parse('%s\tb\n%s\td\n')
33 self.assertEqual(4, len(parts))
34 print(parts)
35
36 # rjust(), use for 'dirs'
37 parts = format_strings.Parse('%2d %s')
38 self.assertEqual(3, len(parts))
39 print(parts)
40
41
42if __name__ == '__main__':
43 unittest.main()