diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-29 16:24:16 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-29 16:24:16 +0000 |
commit | e7108fb5b198d4fe416ce2408afaa86f1020c37d (patch) | |
tree | 95766e6af68b0bd0d832180ce640ef0da868a76e /crates/mbe/src/tests.rs | |
parent | d2a73c61641d065fd70e54a37442386deee6f013 (diff) | |
parent | 706ac8256d878626126756969b48b262d2e187b5 (diff) |
Merge #7491
7491: Simplify mbe match error. r=edwin0cheng a=edwin0cheng
Handle parse error in rule parsing instead of matching in mbe.
bors r+
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/mbe/src/tests.rs')
-rw-r--r-- | crates/mbe/src/tests.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index 8d978163d..1c467facd 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs | |||
@@ -33,19 +33,18 @@ mod rule_parsing { | |||
33 | 33 | ||
34 | #[test] | 34 | #[test] |
35 | fn test_invalid_arms() { | 35 | fn test_invalid_arms() { |
36 | fn check(macro_body: &str, err: &str) { | 36 | fn check(macro_body: &str, err: ParseError) { |
37 | let m = parse_macro_arm(macro_body); | 37 | let m = parse_macro_arm(macro_body); |
38 | assert_eq!(m, Err(ParseError::Expected(String::from(err)))); | 38 | assert_eq!(m, Err(err.into())); |
39 | } | 39 | } |
40 | check("invalid", ParseError::Expected("expected subtree".into())); | ||
40 | 41 | ||
41 | check("invalid", "expected subtree"); | 42 | check("$i:ident => ()", ParseError::Expected("expected subtree".into())); |
43 | check("($i:ident) ()", ParseError::Expected("expected `=`".into())); | ||
44 | check("($($i:ident)_) => ()", ParseError::InvalidRepeat); | ||
42 | 45 | ||
43 | check("$i:ident => ()", "expected subtree"); | 46 | check("($i) => ($i)", ParseError::UnexpectedToken("bad fragment specifier 1".into())); |
44 | check("($i:ident) ()", "expected `=`"); | 47 | check("($i:) => ($i)", ParseError::UnexpectedToken("bad fragment specifier 1".into())); |
45 | check("($($i:ident)_) => ()", "invalid repeat"); | ||
46 | |||
47 | check("($i) => ($i)", "invalid macro definition"); | ||
48 | check("($i:) => ($i)", "invalid macro definition"); | ||
49 | } | 48 | } |
50 | 49 | ||
51 | fn parse_macro_arm(arm_definition: &str) -> Result<crate::MacroRules, ParseError> { | 50 | fn parse_macro_arm(arm_definition: &str) -> Result<crate::MacroRules, ParseError> { |