summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2020-04-03 18:45:57 +0200
committerStefan Behnel <stefan_ml@behnel.de>2020-04-03 19:40:08 +0200
commita3b1cf6f6785da42ddcfecf4778ac0dd3206bad6 (patch)
tree53449c9a7c5e9da73a298b13c65877a06ea98ee4
parent7e004e0a36a8c362a568a5b47a26bfde6f98d621 (diff)
downloadcython-a3b1cf6f6785da42ddcfecf4778ac0dd3206bad6.tar.gz
Explicitly test simple (and optimised) string concatenation in f-strings.
-rw-r--r--tests/run/fstring.pyx59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/run/fstring.pyx b/tests/run/fstring.pyx
index 12410f383..34dc0b175 100644
--- a/tests/run/fstring.pyx
+++ b/tests/run/fstring.pyx
@@ -18,6 +18,65 @@ min_long = LONG_MIN
@cython.test_fail_if_path_exists(
+ "//JoinedStrNode",
+)
+@cython.test_assert_path_exists(
+ "//AddNode",
+)
+def concat_strings(a, b):
+ """
+ >>> concat_strings("", "")
+ x
+ <BLANKLINE>
+ x
+ x
+ x
+ xx
+ >>> concat_strings("a", "")
+ ax
+ a
+ x
+ ax
+ ax
+ axx
+ >>> concat_strings("", "b")
+ x
+ b
+ xb
+ xb
+ xb
+ xxb
+ >>> concat_strings("a", "b")
+ ax
+ ab
+ xb
+ axb
+ axb
+ axxb
+ >>> concat_strings("".join(["a", "b"]), "") # fresh temp string left
+ abx
+ ab
+ x
+ abx
+ abx
+ abxx
+ >>> concat_strings("", "".join(["a", "b"])) # fresh temp string right
+ x
+ ab
+ xab
+ xab
+ xab
+ xxab
+ """
+ print(f"{a}x")
+ print(f"{a}{b}")
+ print(f"x{b}")
+ print(f"{a+'x'}{b}") # fresh temp string left
+ print(f"{a}{'x'+b}") # fresh temp string right
+ print(f"{a+'x'}{'x'+b}") # fresh temp strings right and left
+
+
+@cython.test_fail_if_path_exists(
"//FormattedValueNode",
"//JoinedStrNode",
"//AddNode",