Skip to content

Commit

Permalink
Add tests for f-string check
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbuwen committed Sep 3, 2024
1 parent ee8a4ed commit ba0a46d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test-data/unit/check-string-format.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[case acceptFstringWithoutSpecs]
[builtins fixtures/f_string.pyi]
reveal_type(f"{123} {True} {1 + 2} {'foo'}") # N: Revealed type is "builtins.str"

[case acceptFstringWithValidSpecs]
[builtins fixtures/f_string.pyi]
f"{123:+04} {True!r} {1 + 2:+} {'foo':3<}"

[case denyFstringsWithInvalidSpecs]
[builtins fixtures/f_string.pyi]
f"{'hi':+}" # E: Numeric flags are only allowed for numeric types
f"{123:foo}" # E: Unrecognized format specification "foo"

class MyClass:
pass

f"{MyClass:abc}" # E: Unrecognized format specification "abc"


f"{1} {2} {3:x} {4:y} {5:z}" # E: Unsupported format character "y" # E: Unsupported format character "z"

0 comments on commit ba0a46d

Please sign in to comment.