mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-26 06:24:29 +00:00
Implement except* syntax
This commit is contained in:
parent
8caa28f0f8
commit
c7ed645cc6
4 changed files with 1428 additions and 0 deletions
|
@ -405,6 +405,37 @@ with (0 as a, 1 as b,): pass
|
|||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try() {
|
||||
let parse_ast = parse_program(
|
||||
r#"try:
|
||||
raise ValueError(1)
|
||||
except TypeError as e:
|
||||
print(f'caught {type(e)}')
|
||||
except OSError as e:
|
||||
print(f'caught {type(e)}')"#,
|
||||
"<test>",
|
||||
)
|
||||
.unwrap();
|
||||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_star() {
|
||||
let parse_ast = parse_program(
|
||||
r#"try:
|
||||
raise ExceptionGroup("eg",
|
||||
[ValueError(1), TypeError(2), OSError(3), OSError(4)])
|
||||
except* TypeError as e:
|
||||
print(f'caught {type(e)} with nested {e.exceptions}')
|
||||
except* OSError as e:
|
||||
print(f'caught {type(e)} with nested {e.exceptions}')"#,
|
||||
"<test>",
|
||||
)
|
||||
.unwrap();
|
||||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dict_unpacking() {
|
||||
let parse_ast = parse_expression(r#"{"a": "b", **c, "d": "e"}"#, "<test>").unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue