summaryrefslogtreecommitdiff
path: root/tests/basics/string_format2.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-03-15 13:07:41 +0000
committerDamien George <damien.p.george@gmail.com>2016-03-15 13:07:41 +0000
commitab69ed7dac1bf0ef36238b6289d436e9932180bc (patch)
treee20c26cc428d26d056097cbfc11a49bb0f178ec1 /tests/basics/string_format2.py
parent9996adc37d3f518a30e28cbdfead71a5019e6a60 (diff)
tests: Split large tests into smaller files, to run with a small heap.
All tests in basics/ directory can now run and pass using 64-bit unix port with only a 16k heap (./run-tests --heapsize 16k). Tests in this directory should remain small so they can be used for ports with a small heap.
Diffstat (limited to 'tests/basics/string_format2.py')
-rw-r--r--tests/basics/string_format2.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/basics/string_format2.py b/tests/basics/string_format2.py
new file mode 100644
index 000000000..e211535be
--- /dev/null
+++ b/tests/basics/string_format2.py
@@ -0,0 +1,64 @@
+# comprehensive functionality test for {} format string
+
+int_tests = False # these take a while, and some give wrong results
+char_tests = True
+str_tests = True
+
+def test(fmt, *args):
+ print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
+
+def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
+ fmt = '{'
+ if conv:
+ fmt += '!'
+ fmt += conv
+ fmt += ':'
+ if alignment:
+ fmt += fill
+ fmt += alignment
+ fmt += sign
+ fmt += prefix
+ fmt += width
+ if precision:
+ fmt += '.'
+ fmt += precision
+ fmt += type
+ fmt += '}'
+ test(fmt, arg)
+ if fill == '0' and alignment == '=':
+ fmt = '{:'
+ fmt += sign
+ fmt += prefix
+ fmt += width
+ if precision:
+ fmt += '.'
+ fmt += precision
+ fmt += type
+ fmt += '}'
+ test(fmt, arg)
+
+if int_tests:
+ int_nums = (-1234, -123, -12, -1, 0, 1, 12, 123, 1234, True, False)
+ #int_nums = (-12, -1, 0, 1, 12, True, False)
+ for type in ('', 'b', 'd', 'o', 'x', 'X'):
+ for width in ('', '1', '3', '5', '7'):
+ for alignment in ('', '<', '>', '=', '^'):
+ for fill in ('', ' ', '0', '@'):
+ for sign in ('', '+', '-', ' '):
+ for prefix in ('', '#'):
+ for num in int_nums:
+ test_fmt('', fill, alignment, sign, prefix, width, '', type, num)
+
+if char_tests:
+ for width in ('', '1', '2'):
+ for alignment in ('', '<', '>', '^'):
+ for fill in ('', ' ', '0', '@'):
+ test_fmt('', fill, alignment, '', '', width, '', 'c', 48)
+
+if str_tests:
+ for conv in ('', 'r', 's'):
+ for width in ('', '1', '4', '10'):
+ for alignment in ('', '<', '>', '^'):
+ for fill in ('', ' ', '0', '@'):
+ for str in ('', 'a', 'bcd', 'This is a test with a longer string'):
+ test_fmt(conv, fill, alignment, '', '', width, '', 's', str)