tests: Add full feature and coverage tests for PEP 750 template strings.

Includes corresponding .exp files because this feature is only available in
Python 3.14+.

Tests for `!a` conversion specifier and space after `!` are not included
because they are not supported by MicroPython.

Signed-off-by: Koudai Aono <koxudaxi@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Koudai Aono
2025-11-10 17:15:23 +00:00
committed by Damien George
parent a989585147
commit bdef10a92b
30 changed files with 2517 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
=== Parser error tests ===
Empty expr: SyntaxError - malformed f-string
Whitespace: Template(strings=('', ''), interpolations=(Interpolation(42, ' 42', None, ''),))
=== Error cases ===
Invalid syntax: SyntaxError
Long expr: Error
Mixed concat: SyntaxError
bt prefix: SyntaxError
=== Escape sequence coverage tests ===
Template(strings=('\\8',), interpolations=())
Template(strings=('\\9',), interpolations=())
Template(strings=('\\z',), interpolations=())
Template(strings=('\\k',), interpolations=())
Invalid \x escape: SyntaxError
Invalid \u escape: SyntaxError
Invalid \U escape: SyntaxError
Template(strings=('\x00\x01\xff',), interpolations=())
Template(strings=('A',), interpolations=())
Template(strings=('\u03b1',), interpolations=())
Template(strings=('\u2764',), interpolations=())
Template(strings=('A',), interpolations=())
Template(strings=('\U0001f600',), interpolations=())
Template(strings=('ABC',), interpolations=())
Unicode: Template(strings=('Unicode test:\nEmoji: ', '\nSpecial: ', ''), interpolations=(Interpolation('\U0001f40d', "'\\U0001f40d'", None, ''), Interpolation('\u03b1 \u03b2 \u03b3', "'\\u03b1 \\u03b2 \\u03b3'", None, '')))
=== Trailing whitespace preservation (PEP 750) ===
Expression with trailing spaces: |x|
Expression with both spaces: | x|
Expression with leading spaces: | x|
Trailing whitespace: PASS
=== Error message tests ===
Lone }} rejected (correct)
Unterminated {{ rejected (correct)
=== Triple quote empty interpolation ===
Empty interpolation error: SyntaxError: malformed f-string
Incompatible tests completed!