Skip to content

Commit

Permalink
Add test for empty FStringMiddle tok in lambda expr
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Sep 5, 2023
1 parent 098ee5d commit 1f5c3ea
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/ruff_python_parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,16 @@ allowed {x}"""} string""#;
assert_debug_snapshot!(lex_source(source));
}

#[test]
fn test_fstring_with_lambda_expression() {
let source = r#"
f"{lambda x:{x}}"
f"{(lambda x:{x})}"
"#
.trim();
assert_debug_snapshot!(lex_source(source));
}

fn lex_fstring_error(source: &str) -> FStringErrorType {
match lex(source, Mode::Module).find_map(std::result::Result::err) {
Some(err) => match err.error {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
source: crates/ruff_python_parser/src/lexer.rs
expression: lex_source(source)
---
[
FStringStart,
Lbrace,
Lambda,
Name {
name: "x",
},
Colon,
Lbrace,
Name {
name: "x",
},
Rbrace,
FStringMiddle {
value: "",
is_raw: false,
},
Rbrace,
FStringEnd,
Newline,
FStringStart,
Lbrace,
Lpar,
Lambda,
Name {
name: "x",
},
Colon,
Lbrace,
Name {
name: "x",
},
Rbrace,
Rpar,
Rbrace,
FStringEnd,
Newline,
]

0 comments on commit 1f5c3ea

Please sign in to comment.