diff options
Diffstat (limited to 'tests/run/fstring.pyx')
-rw-r--r-- | tests/run/fstring.pyx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/run/fstring.pyx b/tests/run/fstring.pyx index 45bfaf5e3..88666574c 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", @@ -519,6 +578,27 @@ def percent_s_unicode(u, int i): return u"%s-%d" % (u, i) +@cython.test_assert_path_exists( + "//FormattedValueNode", +) +def sideeffect(l): + """ + >>> class Listish(list): + ... def __format__(self, format_spec): + ... self.append("format called") + ... return repr(self) + ... def append(self, item): + ... list.append(self, item) + ... return self + + >>> l = Listish() + >>> sideeffect(l) if getattr(sys, 'pypy_version_info', ())[:2] != (7,3) else [123, 'format called'] # 7.3.4, 7.3.5 + [123, 'format called'] + """ + f"{l.append(123)}" # unused f-string ! + return list(l) + + ######################################## # await inside f-string |