diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-05 20:02:15 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-05 20:06:15 +0300 |
commit | 75ce9256b2c70bceee6ced26ac7c7bcbd1f1d7f4 (patch) | |
tree | e397a2e3c922a3e3290b022157296e232eb6b556 /tests/basics/string-format-modulo.py | |
parent | 1e82ef3ae8fd8c7570b3c2094fa8b129b354dcdd (diff) | |
download | micropython-75ce9256b2c70bceee6ced26ac7c7bcbd1f1d7f4.tar.gz micropython-75ce9256b2c70bceee6ced26ac7c7bcbd1f1d7f4.zip |
objstr: Implement "%(key)s" % {} formatting for strings and dicts.
Also, make sure that args to "*" format specifiers are bounds-checked
properly and don't lead for segfaults in case of mismatch.
Diffstat (limited to 'tests/basics/string-format-modulo.py')
-rw-r--r-- | tests/basics/string-format-modulo.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/basics/string-format-modulo.py b/tests/basics/string-format-modulo.py index 0e2c1d1096..c8fdc06f68 100644 --- a/tests/basics/string-format-modulo.py +++ b/tests/basics/string-format-modulo.py @@ -48,3 +48,29 @@ print("%#X" % 18) print("%#6o" % 18) print("%#6x" % 18) print("%#06x" % 18) + +print("%*d" % (5, 10)) +print("%*.*d" % (2, 2, 20)) +# TODO: Formatted incorrectly +#print("%*.*d" % (5, 8, 20)) + +# Cases when "*" used and there's not enough values total +try: + print("%*s" % 5) +except TypeError: + print("TypeError") +try: + print("%*.*s" % (1, 15)) +except TypeError: + print("TypeError") + +print("%(foo)s" % {"foo": "bar", "baz": False}) +try: + print("%(foo)s" % {}) +except KeyError: + print("KeyError") +# Using in "*" with dict got to fail +try: + print("%(foo)*s" % {"foo": "bar"}) +except TypeError: + print("TypeError") |