Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
342: Test propagating multiple errors through the routines sections r=ltratt a=ratmice



Co-authored-by: matt rice <ratmice@gmail.com>
  • Loading branch information
bors[bot] and ratmice committed Aug 16, 2022
2 parents cb99d23 + 3ad4f9b commit 6b011af
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cfgrammar/src/lib/yacc/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,4 +2362,36 @@ x"
.into_iter(),
)
}

#[test]
fn test_routines_multiple_errors() {
let mut src = String::from(
"
%start A
%start B
%%
A -> () : 'a';
A -> () : 'a';
%%
",
);
let mut expected_errs = vec![
(
YaccGrammarErrorKind::DuplicateStartDeclaration,
vec![(2, 16), (3, 16)],
),
(YaccGrammarErrorKind::DuplicateRule, vec![(5, 9), (6, 9)]),
];
parse(YaccKind::Grmtools, &src)
.expect_multiple_errors(&src, &mut expected_errs.clone().into_iter());

src.push_str(
"
/* Incomplete comment
",
);
expected_errs.push((YaccGrammarErrorKind::IncompleteComment, vec![(9, 17)]));
parse(YaccKind::Grmtools, &src)
.expect_multiple_errors(&src, &mut expected_errs.clone().into_iter());
}
}
31 changes: 31 additions & 0 deletions lrlex/src/lib/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,4 +1346,35 @@ a\[\]a 'aboxa'
.expect_error_at_line_col(src, LexErrorKind::InvalidStartStateName, 1, 4);
}
}

#[test]
fn test_routines_multiple_errors() {
let mut src = String::from(
r#"
%s A
%s A
%%
a "A"
b "A"
%%
"#,
);

let mut expected_errs = vec![
(LexErrorKind::DuplicateStartState, vec![(2, 12), (3, 12)]),
(LexErrorKind::DuplicateName, vec![(5, 12), (6, 12)]),
];
LRNonStreamingLexerDef::<DefaultLexeme<u8>, u8>::from_str(&src)
.expect_multiple_errors(&src, &mut expected_errs.clone().into_iter());

src.push_str(
"
fn not_supported() {
}
",
);
expected_errs.push((LexErrorKind::RoutinesNotSupported, vec![(7, 9)]));
LRNonStreamingLexerDef::<DefaultLexeme<u8>, u8>::from_str(&src)
.expect_multiple_errors(&src, &mut expected_errs.into_iter());
}
}

0 comments on commit 6b011af

Please sign in to comment.