From b06b2662c9e79a0a07fd13815bb944423ae71344 Mon Sep 17 00:00:00 2001 From: Zanie Date: Wed, 12 Jul 2023 11:24:05 -0500 Subject: [PATCH] Add test for tuple bounds --- parser/src/parser.rs | 10 +++ ...ss_with_generic_type_with_tuple_bound.snap | 81 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_tuple_bound.snap diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 3f61989..4b38270 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -656,6 +656,16 @@ class Foo[T: str](A, B): insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); } + #[test] + #[cfg(feature = "all-nodes-with-ranges")] + fn test_parse_class_with_generic_type_with_tuple_bound() { + let source = "\ +class Foo[T: (str, bytes)](A, B): + pass +"; + insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); + } + #[test] #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_class_with_multiple_generic_types() { diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_tuple_bound.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_tuple_bound.snap new file mode 100644 index 0000000..b137804 --- /dev/null +++ b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_tuple_bound.snap @@ -0,0 +1,81 @@ +--- +source: parser/src/parser.rs +expression: "ast::Suite::parse(source, \"\").unwrap()" +--- +[ + ClassDef( + StmtClassDef { + range: 0..40, + name: Identifier( + "Foo", + ), + bases: [ + Name( + ExprName { + range: 27..28, + id: Identifier( + "A", + ), + ctx: Load, + }, + ), + Name( + ExprName { + range: 30..31, + id: Identifier( + "B", + ), + ctx: Load, + }, + ), + ], + keywords: [], + body: [ + Pass( + StmtPass { + range: 36..40, + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 10..25, + name: Identifier( + "T", + ), + bound: Some( + Tuple( + ExprTuple { + range: 13..25, + elts: [ + Name( + ExprName { + range: 14..17, + id: Identifier( + "str", + ), + ctx: Load, + }, + ), + Name( + ExprName { + range: 19..24, + id: Identifier( + "bytes", + ), + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), + ), + }, + ), + ], + }, + ), +]