Consolidate tests and add coverage for trailing comma

This commit is contained in:
Zanie 2023-07-13 08:51:23 -05:00
parent e0a8f5b7b3
commit 3ec64e124a
9 changed files with 392 additions and 513 deletions

View file

@ -638,70 +638,31 @@ class Foo(A, B):
#[test] #[test]
#[cfg(feature = "all-nodes-with-ranges")] #[cfg(feature = "all-nodes-with-ranges")]
fn test_parse_class_with_generic_type() { fn test_parse_class_generic_types() {
let source = "\ let source = "\
class Foo[T](A, B): # TypeVar
pass class Foo[T](): ...
";
insta::assert_debug_snapshot!(ast::Suite::parse(source, "<test>").unwrap());
}
#[test] # TypeVar with bound
#[cfg(feature = "all-nodes-with-ranges")] class Foo[T: str](): ...
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, "<test>").unwrap());
}
#[test] # TypeVar with tuple bound
#[cfg(feature = "all-nodes-with-ranges")] class Foo[T: (str, bytes)](): ...
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, "<test>").unwrap());
}
#[test] # Multiple TypeVar
#[cfg(feature = "all-nodes-with-ranges")] class Foo[T, U](): ...
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, "<test>").unwrap());
}
#[test] # Trailing comma
#[cfg(feature = "all-nodes-with-ranges")] class Foo[T, U,](): ...
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, "<test>").unwrap());
}
# TypeVarTuple
class Foo[*Ts](): ...
#[test] # ParamSpec
#[cfg(feature = "all-nodes-with-ranges")] class Foo[**P](): ...
fn test_parse_class_with_generic_param_spec() {
let source = "\
class Foo[**P](A, B):
pass
";
insta::assert_debug_snapshot!(ast::Suite::parse(source, "<test>").unwrap());
}
#[test] # Mixed types
#[cfg(feature = "all-nodes-with-ranges")] class Foo[X, Y: str, *U, **P]():
fn test_parse_class_with_all_possible_generic_types() {
let source = "\
class Foo[X, Y: str, *U, **P](A, B):
pass pass
"; ";
insta::assert_debug_snapshot!(ast::Suite::parse(source, "<test>").unwrap()); insta::assert_debug_snapshot!(ast::Suite::parse(source, "<test>").unwrap());

View file

@ -0,0 +1,375 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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",
),
},
),
],
},
),
]

View file

@ -1,89 +0,0 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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",
),
},
),
],
},
),
]

View file

@ -1,53 +0,0 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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",
),
},
),
],
},
),
]

View file

@ -1,54 +0,0 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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,
},
),
],
},
),
]

View file

@ -1,53 +0,0 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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",
),
},
),
],
},
),
]

View file

@ -1,64 +0,0 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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,
},
),
),
},
),
],
},
),
]

View file

@ -1,81 +0,0 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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,
},
),
),
},
),
],
},
),
]

View file

@ -1,63 +0,0 @@
---
source: parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").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,
},
),
],
},
),
]