From 1536efcb1088e136355efac2d0b4efee5f8a5347 Mon Sep 17 00:00:00 2001 From: Glyphack Date: Sat, 13 Apr 2024 15:52:57 +0200 Subject: [PATCH] temp --- crates/ruff_python_parser/src/parser.rs | 75 +++++++++++ ...r__tests__alias_stringized_annotation.snap | 117 ++++++++++++++++++ ..._parser__tests__stringized_annotation.snap | 70 +++++++++++ 3 files changed, 262 insertions(+) create mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__alias_stringized_annotation.snap create mode 100644 crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__stringized_annotation.snap diff --git a/crates/ruff_python_parser/src/parser.rs b/crates/ruff_python_parser/src/parser.rs index 659fac0b4aff87..85c0f281542fc7 100644 --- a/crates/ruff_python_parser/src/parser.rs +++ b/crates/ruff_python_parser/src/parser.rs @@ -1521,4 +1521,79 @@ a,b .unwrap(); insta::assert_debug_snapshot!(parse_ast); } +<<<<<<< Updated upstream +||||||| Stash base + + #[test] + fn test_stringized_annotation() { + let parse_ast = parse_suite( + r#" +from typing_extensions import TypeAlias + + +Alias1 = ( + int + | str + | bool +) # parentheses required + +Alias2: TypeAlias = """ + int + | str + | bool +""" +"# + .trim(), + ) + .unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } +======= + + #[test] + fn test_alias_stringized_annotation() { + let parse_ast = parse_suite( + r#" +from typing_extensions import TypeAlias + + +Alias1 = ( + int + | str + | bool +) # parentheses required + +Alias2: TypeAlias = """ + int + | str + | bool +""" +"# + .trim(), + ) + .unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } + + #[test] + fn test_stringized_annotation() { + let parse_ast = parse_suite( + r#" +x: """ + + int | + str +""" + +y: """( + int | + str +)""" +"# + .trim(), + ) + .unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } +>>>>>>> Stashed changes } diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__alias_stringized_annotation.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__alias_stringized_annotation.snap new file mode 100644 index 00000000000000..72fb89e2aef058 --- /dev/null +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__alias_stringized_annotation.snap @@ -0,0 +1,117 @@ +--- +source: crates/ruff_python_parser/src/parser.rs +expression: parse_ast +--- +[ + ImportFrom( + StmtImportFrom { + range: 0..39, + module: Some( + Identifier { + id: "typing_extensions", + range: 5..22, + }, + ), + names: [ + Alias { + range: 30..39, + name: Identifier { + id: "TypeAlias", + range: 30..39, + }, + asname: None, + }, + ], + level: Some( + 0, + ), + }, + ), + Assign( + StmtAssign { + range: 42..83, + targets: [ + Name( + ExprName { + range: 42..48, + id: "Alias1", + ctx: Store, + }, + ), + ], + value: BinOp( + ExprBinOp { + range: 57..81, + left: BinOp( + ExprBinOp { + range: 57..70, + left: Name( + ExprName { + range: 57..60, + id: "int", + ctx: Load, + }, + ), + op: BitOr, + right: Name( + ExprName { + range: 67..70, + id: "str", + ctx: Load, + }, + ), + }, + ), + op: BitOr, + right: Name( + ExprName { + range: 77..81, + id: "bool", + ctx: Load, + }, + ), + }, + ), + }, + ), + AnnAssign( + StmtAnnAssign { + range: 109..165, + target: Name( + ExprName { + range: 109..115, + id: "Alias2", + ctx: Store, + }, + ), + annotation: Name( + ExprName { + range: 117..126, + id: "TypeAlias", + ctx: Load, + }, + ), + value: Some( + StringLiteral( + ExprStringLiteral { + range: 129..165, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 129..165, + value: "\n int\n | str\n | bool\n", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: true, + }, + }, + ), + }, + }, + ), + ), + simple: true, + }, + ), +] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__stringized_annotation.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__stringized_annotation.snap new file mode 100644 index 00000000000000..3460da7d0041b5 --- /dev/null +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__stringized_annotation.snap @@ -0,0 +1,70 @@ +--- +source: crates/ruff_python_parser/src/parser.rs +expression: parse_ast +--- +[ + AnnAssign( + StmtAnnAssign { + range: 0..27, + target: Name( + ExprName { + range: 0..1, + id: "x", + ctx: Store, + }, + ), + annotation: StringLiteral( + ExprStringLiteral { + range: 3..27, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 3..27, + value: "\n\n int |\n str\n", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: true, + }, + }, + ), + }, + }, + ), + value: None, + simple: true, + }, + ), + AnnAssign( + StmtAnnAssign { + range: 29..59, + target: Name( + ExprName { + range: 29..30, + id: "y", + ctx: Store, + }, + ), + annotation: StringLiteral( + ExprStringLiteral { + range: 32..59, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 32..59, + value: "(\n int |\n str\n)", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: true, + }, + }, + ), + }, + }, + ), + value: None, + simple: true, + }, + ), +]