test: add parser test

Signed-off-by: 11happy <bhuminjaysoni@gmail.com>
This commit is contained in:
11happy 2025-12-02 07:10:39 +00:00
parent f1c394ba76
commit f7bd94bd27
3 changed files with 182 additions and 0 deletions

View File

@ -0,0 +1,108 @@
---
source: crates/ruff_python_parser/src/parser/tests.rs
expression: result
---
Parsed {
syntax: ModExpression {
node_index: NodeIndex(None),
range: 0..25,
body: DictComp(
ExprDictComp {
node_index: NodeIndex(None),
range: 0..25,
key: Name(
ExprName {
node_index: NodeIndex(None),
range: 1..2,
id: Name("x"),
ctx: Load,
},
),
value: BinOp(
ExprBinOp {
node_index: NodeIndex(None),
range: 4..7,
left: Name(
ExprName {
node_index: NodeIndex(None),
range: 7..7,
id: Name(""),
ctx: Invalid,
},
),
op: Pow,
right: Name(
ExprName {
node_index: NodeIndex(None),
range: 6..7,
id: Name("y"),
ctx: Load,
},
),
},
),
generators: [
Comprehension {
range: 8..24,
node_index: NodeIndex(None),
target: Tuple(
ExprTuple {
node_index: NodeIndex(None),
range: 12..16,
elts: [
Name(
ExprName {
node_index: NodeIndex(None),
range: 12..13,
id: Name("x"),
ctx: Store,
},
),
Name(
ExprName {
node_index: NodeIndex(None),
range: 15..16,
id: Name("y"),
ctx: Store,
},
),
],
ctx: Store,
parenthesized: false,
},
),
iter: Name(
ExprName {
node_index: NodeIndex(None),
range: 20..24,
id: Name("data"),
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
},
tokens: Tokens {
raw: [
Lbrace 0..1,
Name 1..2,
Colon 2..3,
DoubleStar 4..6,
Name 6..7,
For 8..11,
Name 12..13,
Comma 13..14,
Name 15..16,
In 17..19,
Name 20..24,
Rbrace 24..25,
Newline 25..25,
],
},
errors: [],
unsupported_syntax_errors: [],
}

View File

@ -0,0 +1,56 @@
---
source: crates/ruff_python_parser/src/parser/tests.rs
expression: result
---
Parsed {
syntax: ModExpression {
node_index: NodeIndex(None),
range: 0..13,
body: Call(
ExprCall {
node_index: NodeIndex(None),
range: 0..13,
func: Name(
ExprName {
node_index: NodeIndex(None),
range: 0..3,
id: Name("foo"),
ctx: Load,
},
),
arguments: Arguments {
range: 3..13,
node_index: NodeIndex(None),
args: [],
keywords: [
Keyword {
range: 4..12,
node_index: NodeIndex(None),
arg: None,
value: Name(
ExprName {
node_index: NodeIndex(None),
range: 6..12,
id: Name("kwargs"),
ctx: Load,
},
),
},
],
},
},
),
},
tokens: Tokens {
raw: [
Name 0..3,
Lpar 3..4,
DoubleStar 4..6,
Name 6..12,
Rpar 12..13,
Newline 13..13,
],
},
errors: [],
unsupported_syntax_errors: [],
}

View File

@ -157,3 +157,21 @@ t"i}'"#;
insta::assert_debug_snapshot!(error);
}
#[test]
fn test_dict_double_star_missing_left_operand() {
let source = r#"{x: **y for x, y in data}"#;
let parsed = parse_expression(source);
assert!(parsed.is_ok());
let result = parsed.unwrap();
insta::assert_debug_snapshot!(result);
}
#[test]
fn test_function_kwargs() {
let source = r#"foo(**kwargs)"#;
let parsed = parse_expression(source);
assert!(parsed.is_ok());
let result = parsed.unwrap();
insta::assert_debug_snapshot!(result);
}