From 3ec64e124aa03c52136cfc5761d98cb021252943 Mon Sep 17 00:00:00 2001 From: Zanie Date: Thu, 13 Jul 2023 08:51:23 -0500 Subject: [PATCH] Consolidate tests and add coverage for trailing comma --- parser/src/parser.rs | 73 +--- ...ser__tests__parse_class_generic_types.snap | 375 ++++++++++++++++++ ...class_with_all_possible_generic_types.snap | 89 ----- ...__parse_class_with_generic_param_spec.snap | 53 --- ..._tests__parse_class_with_generic_type.snap | 54 --- ...rse_class_with_generic_type_var_tuple.snap | 53 --- ...se_class_with_generic_type_with_bound.snap | 64 --- ...ss_with_generic_type_with_tuple_bound.snap | 81 ---- ...rse_class_with_multiple_generic_types.snap | 63 --- 9 files changed, 392 insertions(+), 513 deletions(-) create mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_generic_types.snap delete mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_all_possible_generic_types.snap delete mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_param_spec.snap delete mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type.snap delete mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_var_tuple.snap delete mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_bound.snap delete mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_tuple_bound.snap delete mode 100644 parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_multiple_generic_types.snap diff --git a/parser/src/parser.rs b/parser/src/parser.rs index bd26ab2..7964cce 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -638,70 +638,31 @@ class Foo(A, B): #[test] #[cfg(feature = "all-nodes-with-ranges")] - fn test_parse_class_with_generic_type() { + fn test_parse_class_generic_types() { let source = "\ -class Foo[T](A, B): - pass -"; - insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); - } +# TypeVar +class Foo[T](): ... - #[test] - #[cfg(feature = "all-nodes-with-ranges")] - fn test_parse_class_with_generic_type_with_bound() { - let source = "\ -class Foo[T: str](A, B): - pass -"; - insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); - } +# TypeVar with bound +class Foo[T: str](): ... - #[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()); - } +# TypeVar with tuple bound +class Foo[T: (str, bytes)](): ... - #[test] - #[cfg(feature = "all-nodes-with-ranges")] - fn test_parse_class_with_multiple_generic_types() { - let source = "\ -class Foo[T, U](A, B): - pass -"; - insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); - } +# Multiple TypeVar +class Foo[T, U](): ... - #[test] - #[cfg(feature = "all-nodes-with-ranges")] - fn test_parse_class_with_generic_type_var_tuple() { - let source = "\ -class Foo[*U](A, B): - pass -"; - insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); - } +# Trailing comma +class Foo[T, U,](): ... +# TypeVarTuple +class Foo[*Ts](): ... - #[test] - #[cfg(feature = "all-nodes-with-ranges")] - fn test_parse_class_with_generic_param_spec() { - let source = "\ -class Foo[**P](A, B): - pass -"; - insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); - } +# ParamSpec +class Foo[**P](): ... - #[test] - #[cfg(feature = "all-nodes-with-ranges")] - fn test_parse_class_with_all_possible_generic_types() { - let source = "\ -class Foo[X, Y: str, *U, **P](A, B): +# Mixed types +class Foo[X, Y: str, *U, **P](): pass "; insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_generic_types.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_generic_types.snap new file mode 100644 index 0000000..c48429b --- /dev/null +++ b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_generic_types.snap @@ -0,0 +1,375 @@ +--- +source: parser/src/parser.rs +expression: "ast::Suite::parse(source, \"\").unwrap()" +--- +[ + ClassDef( + StmtClassDef { + range: 10..29, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Expr( + StmtExpr { + range: 26..29, + value: Constant( + ExprConstant { + range: 26..29, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 20..21, + name: Identifier( + "T", + ), + bound: None, + }, + ), + ], + }, + ), + ClassDef( + StmtClassDef { + range: 52..76, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Expr( + StmtExpr { + range: 73..76, + value: Constant( + ExprConstant { + range: 73..76, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 62..68, + name: Identifier( + "T", + ), + bound: Some( + Name( + ExprName { + range: 65..68, + id: Identifier( + "str", + ), + ctx: Load, + }, + ), + ), + }, + ), + ], + }, + ), + ClassDef( + StmtClassDef { + range: 105..138, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Expr( + StmtExpr { + range: 135..138, + value: Constant( + ExprConstant { + range: 135..138, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 115..130, + name: Identifier( + "T", + ), + bound: Some( + Tuple( + ExprTuple { + range: 118..130, + elts: [ + Name( + ExprName { + range: 119..122, + id: Identifier( + "str", + ), + ctx: Load, + }, + ), + Name( + ExprName { + range: 124..129, + id: Identifier( + "bytes", + ), + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), + ), + }, + ), + ], + }, + ), + ClassDef( + StmtClassDef { + range: 159..181, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Expr( + StmtExpr { + range: 178..181, + value: Constant( + ExprConstant { + range: 178..181, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 169..170, + name: Identifier( + "T", + ), + bound: None, + }, + ), + TypeVar( + TypeParamTypeVar { + range: 172..173, + name: Identifier( + "U", + ), + bound: None, + }, + ), + ], + }, + ), + ClassDef( + StmtClassDef { + range: 200..223, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Expr( + StmtExpr { + range: 220..223, + value: Constant( + ExprConstant { + range: 220..223, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 210..211, + name: Identifier( + "T", + ), + bound: None, + }, + ), + TypeVar( + TypeParamTypeVar { + range: 213..214, + name: Identifier( + "U", + ), + bound: None, + }, + ), + ], + }, + ), + ClassDef( + StmtClassDef { + range: 240..261, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Expr( + StmtExpr { + range: 258..261, + value: Constant( + ExprConstant { + range: 258..261, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVarTuple( + TypeParamTypeVarTuple { + range: 250..253, + name: Identifier( + "Ts", + ), + }, + ), + ], + }, + ), + ClassDef( + StmtClassDef { + range: 275..296, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Expr( + StmtExpr { + range: 293..296, + value: Constant( + ExprConstant { + range: 293..296, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], + decorator_list: [], + type_params: [ + ParamSpec( + TypeParamParamSpec { + range: 285..288, + name: Identifier( + "P", + ), + }, + ), + ], + }, + ), + ClassDef( + StmtClassDef { + range: 312..351, + name: Identifier( + "Foo", + ), + bases: [], + keywords: [], + body: [ + Pass( + StmtPass { + range: 347..351, + }, + ), + ], + decorator_list: [], + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 322..323, + name: Identifier( + "X", + ), + bound: None, + }, + ), + TypeVar( + TypeParamTypeVar { + range: 325..331, + name: Identifier( + "Y", + ), + bound: Some( + Name( + ExprName { + range: 328..331, + id: Identifier( + "str", + ), + ctx: Load, + }, + ), + ), + }, + ), + TypeVarTuple( + TypeParamTypeVarTuple { + range: 333..335, + name: Identifier( + "U", + ), + }, + ), + ParamSpec( + TypeParamParamSpec { + range: 337..340, + name: Identifier( + "P", + ), + }, + ), + ], + }, + ), +] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_all_possible_generic_types.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_all_possible_generic_types.snap deleted file mode 100644 index 7eeebda..0000000 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_all_possible_generic_types.snap +++ /dev/null @@ -1,89 +0,0 @@ ---- -source: parser/src/parser.rs -expression: "ast::Suite::parse(source, \"\").unwrap()" ---- -[ - ClassDef( - StmtClassDef { - range: 0..43, - name: Identifier( - "Foo", - ), - bases: [ - Name( - ExprName { - range: 30..31, - id: Identifier( - "A", - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 33..34, - id: Identifier( - "B", - ), - ctx: Load, - }, - ), - ], - keywords: [], - body: [ - Pass( - StmtPass { - range: 39..43, - }, - ), - ], - decorator_list: [], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 10..11, - name: Identifier( - "X", - ), - bound: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 13..19, - name: Identifier( - "Y", - ), - bound: Some( - Name( - ExprName { - range: 16..19, - id: Identifier( - "str", - ), - ctx: Load, - }, - ), - ), - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 21..23, - name: Identifier( - "U", - ), - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 25..28, - name: Identifier( - "P", - ), - }, - ), - ], - }, - ), -] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_param_spec.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_param_spec.snap deleted file mode 100644 index 95855fd..0000000 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_param_spec.snap +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: parser/src/parser.rs -expression: "ast::Suite::parse(source, \"\").unwrap()" ---- -[ - ClassDef( - StmtClassDef { - range: 0..28, - name: Identifier( - "Foo", - ), - bases: [ - Name( - ExprName { - range: 15..16, - id: Identifier( - "A", - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 18..19, - id: Identifier( - "B", - ), - ctx: Load, - }, - ), - ], - keywords: [], - body: [ - Pass( - StmtPass { - range: 24..28, - }, - ), - ], - decorator_list: [], - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 10..13, - name: Identifier( - "P", - ), - }, - ), - ], - }, - ), -] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type.snap deleted file mode 100644 index 19e6bc6..0000000 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type.snap +++ /dev/null @@ -1,54 +0,0 @@ ---- -source: parser/src/parser.rs -expression: "ast::Suite::parse(source, \"\").unwrap()" ---- -[ - ClassDef( - StmtClassDef { - range: 0..26, - name: Identifier( - "Foo", - ), - bases: [ - Name( - ExprName { - range: 13..14, - id: Identifier( - "A", - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 16..17, - id: Identifier( - "B", - ), - ctx: Load, - }, - ), - ], - keywords: [], - body: [ - Pass( - StmtPass { - range: 22..26, - }, - ), - ], - decorator_list: [], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 10..11, - name: Identifier( - "T", - ), - bound: None, - }, - ), - ], - }, - ), -] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_var_tuple.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_var_tuple.snap deleted file mode 100644 index bfe79f2..0000000 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_var_tuple.snap +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: parser/src/parser.rs -expression: "ast::Suite::parse(source, \"\").unwrap()" ---- -[ - ClassDef( - StmtClassDef { - range: 0..27, - name: Identifier( - "Foo", - ), - bases: [ - Name( - ExprName { - range: 14..15, - id: Identifier( - "A", - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 17..18, - id: Identifier( - "B", - ), - ctx: Load, - }, - ), - ], - keywords: [], - body: [ - Pass( - StmtPass { - range: 23..27, - }, - ), - ], - decorator_list: [], - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 10..12, - name: Identifier( - "U", - ), - }, - ), - ], - }, - ), -] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_bound.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_bound.snap deleted file mode 100644 index 5cff159..0000000 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_bound.snap +++ /dev/null @@ -1,64 +0,0 @@ ---- -source: parser/src/parser.rs -expression: "ast::Suite::parse(source, \"\").unwrap()" ---- -[ - ClassDef( - StmtClassDef { - range: 0..31, - name: Identifier( - "Foo", - ), - bases: [ - Name( - ExprName { - range: 18..19, - id: Identifier( - "A", - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 21..22, - id: Identifier( - "B", - ), - ctx: Load, - }, - ), - ], - keywords: [], - body: [ - Pass( - StmtPass { - range: 27..31, - }, - ), - ], - decorator_list: [], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 10..16, - name: Identifier( - "T", - ), - bound: Some( - Name( - ExprName { - range: 13..16, - id: Identifier( - "str", - ), - ctx: Load, - }, - ), - ), - }, - ), - ], - }, - ), -] 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 deleted file mode 100644 index b137804..0000000 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_generic_type_with_tuple_bound.snap +++ /dev/null @@ -1,81 +0,0 @@ ---- -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, - }, - ), - ), - }, - ), - ], - }, - ), -] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_multiple_generic_types.snap b/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_multiple_generic_types.snap deleted file mode 100644 index 69cc628..0000000 --- a/parser/src/snapshots/rustpython_parser__parser__tests__parse_class_with_multiple_generic_types.snap +++ /dev/null @@ -1,63 +0,0 @@ ---- -source: parser/src/parser.rs -expression: "ast::Suite::parse(source, \"\").unwrap()" ---- -[ - ClassDef( - StmtClassDef { - range: 0..29, - name: Identifier( - "Foo", - ), - bases: [ - Name( - ExprName { - range: 16..17, - id: Identifier( - "A", - ), - ctx: Load, - }, - ), - Name( - ExprName { - range: 19..20, - id: Identifier( - "B", - ), - ctx: Load, - }, - ), - ], - keywords: [], - body: [ - Pass( - StmtPass { - range: 25..29, - }, - ), - ], - decorator_list: [], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 10..11, - name: Identifier( - "T", - ), - bound: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 13..14, - name: Identifier( - "U", - ), - bound: None, - }, - ), - ], - }, - ), -]