mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-21 12:05:27 +00:00
Move tests for with into parser.
This commit is contained in:
parent
e4d2344c41
commit
bf715ab1ca
4 changed files with 58 additions and 63 deletions
|
@ -33,4 +33,3 @@ mod python;
|
||||||
mod context;
|
mod context;
|
||||||
mod string;
|
mod string;
|
||||||
pub mod token;
|
pub mod token;
|
||||||
mod with;
|
|
||||||
|
|
|
@ -259,4 +259,61 @@ class Foo(A, B):
|
||||||
let parse_ast = parse_expression(&source, "<test>").unwrap();
|
let parse_ast = parse_expression(&source, "<test>").unwrap();
|
||||||
insta::assert_debug_snapshot!(parse_ast);
|
insta::assert_debug_snapshot!(parse_ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_with_statement() {
|
||||||
|
let source = "\
|
||||||
|
with 0: pass
|
||||||
|
with 0 as x: pass
|
||||||
|
with 0, 1: pass
|
||||||
|
with 0 as x, 1 as y: pass
|
||||||
|
with 0 if 1 else 2: pass
|
||||||
|
with 0 if 1 else 2 as x: pass
|
||||||
|
with (): pass
|
||||||
|
with () as x: pass
|
||||||
|
with (0): pass
|
||||||
|
with (0) as x: pass
|
||||||
|
with (0,): pass
|
||||||
|
with (0,) as x: pass
|
||||||
|
with (0, 1): pass
|
||||||
|
with (0, 1) as x: pass
|
||||||
|
with (*a,): pass
|
||||||
|
with (*a,) as x: pass
|
||||||
|
with (0, *a): pass
|
||||||
|
with (0, *a) as x: pass
|
||||||
|
with (a := 0): pass
|
||||||
|
with (a := 0) as x: pass
|
||||||
|
with (a := 0, b := 1): pass
|
||||||
|
with (a := 0, b := 1) as x: pass
|
||||||
|
with (0 as a): pass
|
||||||
|
with (0 as a,): pass
|
||||||
|
with (0 as a, 1 as b): pass
|
||||||
|
with (0 as a, 1 as b,): pass
|
||||||
|
";
|
||||||
|
insta::assert_debug_snapshot!(parse_program(source, "<test>").unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_with_statement_invalid() {
|
||||||
|
for source in [
|
||||||
|
"with 0,: pass",
|
||||||
|
"with 0 as x,: pass",
|
||||||
|
"with 0 as *x: pass",
|
||||||
|
"with *a: pass",
|
||||||
|
"with *a as x: pass",
|
||||||
|
"with (*a): pass",
|
||||||
|
"with (*a) as x: pass",
|
||||||
|
"with *a, 0 as x: pass",
|
||||||
|
"with (*a, 0 as x): pass",
|
||||||
|
"with 0 as x, *a: pass",
|
||||||
|
"with (0 as x, *a): pass",
|
||||||
|
"with (0 as x) as y: pass",
|
||||||
|
"with (0 as x), 1: pass",
|
||||||
|
"with ((0 as x)): pass",
|
||||||
|
"with a := 0 as x: pass",
|
||||||
|
"with (a := 0 as x): pass",
|
||||||
|
] {
|
||||||
|
assert!(parse_program(source, "<test>").is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
source: compiler/parser/src/with.rs
|
source: compiler/parser/src/parser.rs
|
||||||
expression: "parse_program(source, \"<test>\").unwrap()"
|
expression: "parse_program(source, \"<test>\").unwrap()"
|
||||||
---
|
---
|
||||||
[
|
[
|
|
@ -1,61 +0,0 @@
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::parser::parse_program;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_with_statement() {
|
|
||||||
let source = "\
|
|
||||||
with 0: pass
|
|
||||||
with 0 as x: pass
|
|
||||||
with 0, 1: pass
|
|
||||||
with 0 as x, 1 as y: pass
|
|
||||||
with 0 if 1 else 2: pass
|
|
||||||
with 0 if 1 else 2 as x: pass
|
|
||||||
with (): pass
|
|
||||||
with () as x: pass
|
|
||||||
with (0): pass
|
|
||||||
with (0) as x: pass
|
|
||||||
with (0,): pass
|
|
||||||
with (0,) as x: pass
|
|
||||||
with (0, 1): pass
|
|
||||||
with (0, 1) as x: pass
|
|
||||||
with (*a,): pass
|
|
||||||
with (*a,) as x: pass
|
|
||||||
with (0, *a): pass
|
|
||||||
with (0, *a) as x: pass
|
|
||||||
with (a := 0): pass
|
|
||||||
with (a := 0) as x: pass
|
|
||||||
with (a := 0, b := 1): pass
|
|
||||||
with (a := 0, b := 1) as x: pass
|
|
||||||
with (0 as a): pass
|
|
||||||
with (0 as a,): pass
|
|
||||||
with (0 as a, 1 as b): pass
|
|
||||||
with (0 as a, 1 as b,): pass
|
|
||||||
";
|
|
||||||
insta::assert_debug_snapshot!(parse_program(source, "<test>").unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_with_statement_invalid() {
|
|
||||||
for source in [
|
|
||||||
"with 0,: pass",
|
|
||||||
"with 0 as x,: pass",
|
|
||||||
"with 0 as *x: pass",
|
|
||||||
"with *a: pass",
|
|
||||||
"with *a as x: pass",
|
|
||||||
"with (*a): pass",
|
|
||||||
"with (*a) as x: pass",
|
|
||||||
"with *a, 0 as x: pass",
|
|
||||||
"with (*a, 0 as x): pass",
|
|
||||||
"with 0 as x, *a: pass",
|
|
||||||
"with (0 as x, *a): pass",
|
|
||||||
"with (0 as x) as y: pass",
|
|
||||||
"with (0 as x), 1: pass",
|
|
||||||
"with ((0 as x)): pass",
|
|
||||||
"with a := 0 as x: pass",
|
|
||||||
"with (a := 0 as x): pass",
|
|
||||||
] {
|
|
||||||
assert!(parse_program(source, "<test>").is_err());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue