summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
authorpohmelie <multisosnooley@gmail.com>2016-01-29 12:09:10 +0300
committerDamien George <damien.p.george@gmail.com>2016-02-02 16:25:24 +0000
commite3a29de1dc7649656228460caf72e7841440a373 (patch)
treec3b4f936989c7888300b7e2198dcec05a01c7379 /tests/basics
parent2bd758fe96e2913f48c1a0fdccafddc3dfb31cf9 (diff)
downloadmicropython-e3a29de1dc7649656228460caf72e7841440a373.tar.gz
micropython-e3a29de1dc7649656228460caf72e7841440a373.zip
py/objstr: For str.format, add nested/computed fields support.
Eg: '{:{}}'.format(123, '>20') @pohmelie was the original author of this patch, but @dpgeorge made significant changes to reduce code size and improve efficiency.
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/string_format.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/basics/string_format.py b/tests/basics/string_format.py
index 7fb53cb491..e07f0d9533 100644
--- a/tests/basics/string_format.py
+++ b/tests/basics/string_format.py
@@ -66,6 +66,14 @@ test("{:>20}", "foo")
test("{:^20}", "foo")
test("{:<20}", "foo")
+# nested format specifiers
+print("{:{}}".format(123, '#>10'))
+print("{:{}{}{}}".format(123, '#', '>', '10'))
+print("{0:{1}{2}}".format(123, '#>', '10'))
+print("{text:{align}{width}}".format(text="foo", align="<", width=20))
+print("{text:{align}{width}}".format(text="foo", align="^", width=10))
+print("{text:{align}{width}}".format(text="foo", align=">", width=30))
+
print("{foo}/foo".format(foo="bar"))
print("{}".format(123, foo="bar"))
print("{}-{foo}".format(123, foo="bar"))