From 75ce9256b2c70bceee6ced26ac7c7bcbd1f1d7f4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 5 Jun 2014 20:02:15 +0300 Subject: 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. --- tests/basics/string-format-modulo.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/basics/string-format-modulo.py') 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") -- cgit v1.2.3