diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 77f836e40b..8ecce8d604 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -853,4 +853,24 @@ def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ... .unwrap(); insta::assert_debug_snapshot!(parse_ast); } + + #[test] + #[cfg(not(feature = "all-nodes-with-ranges"))] + fn decorator_ranges() { + let parse_ast = parse_program( + r#" +@my_decorator +def test(): + pass + +@class_decorator +class Abcd: + pass +"# + .trim(), + "", + ) + .unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } } diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__decorator_ranges.snap b/parser/src/snapshots/rustpython_parser__parser__tests__decorator_ranges.snap new file mode 100644 index 0000000000..41910455a7 --- /dev/null +++ b/parser/src/snapshots/rustpython_parser__parser__tests__decorator_ranges.snap @@ -0,0 +1,72 @@ +--- +source: parser/src/parser.rs +expression: parse_ast +--- +[ + FunctionDef( + StmtFunctionDef { + range: 0..34, + name: Identifier( + "test", + ), + args: Arguments { + range: (), + posonlyargs: [], + args: [], + vararg: None, + kwonlyargs: [], + kw_defaults: [], + kwarg: None, + defaults: [], + }, + body: [ + Pass( + StmtPass { + range: 30..34, + }, + ), + ], + decorator_list: [ + Name( + ExprName { + range: 1..13, + id: Identifier( + "my_decorator", + ), + ctx: Load, + }, + ), + ], + returns: None, + type_comment: None, + }, + ), + ClassDef( + StmtClassDef { + range: 40..77, + name: Identifier( + "Abcd", + ), + bases: [], + keywords: [], + body: [ + Pass( + StmtPass { + range: 73..77, + }, + ), + ], + decorator_list: [ + Name( + ExprName { + range: 41..56, + id: Identifier( + "class_decorator", + ), + ctx: Load, + }, + ), + ], + }, + ), +]