From 228d1181b7caa54e062f9082b56c8ba2fd15bbb9 Mon Sep 17 00:00:00 2001 From: Andrew Baxter <> Date: Tue, 15 Oct 2024 19:55:10 +0900 Subject: [PATCH] Add regression test for #16, subtract overflow --- tests/build.rs | 4 ++ tests/src/glr/mod.rs | 1 + .../inline.rustemo | 43 +++++++++++++++++++ .../issue_16_subtract_overflow_panic/mod.rs | 22 ++++++++++ tests/src/glr/regressions/mod.rs | 1 + 5 files changed, 71 insertions(+) create mode 100644 tests/src/glr/regressions/issue_16_subtract_overflow_panic/inline.rustemo create mode 100644 tests/src/glr/regressions/issue_16_subtract_overflow_panic/mod.rs create mode 100644 tests/src/glr/regressions/mod.rs diff --git a/tests/build.rs b/tests/build.rs index 9b991a70..13225db1 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -200,6 +200,10 @@ fn main() { "glr/special/farshi_g8", Box::new(|s| s.parser_algo(ParserAlgo::GLR)), ), + ( + "glr/regressions/issue_16_subtract_overflow_panic", + Box::new(|s| s.parser_algo(ParserAlgo::GLR)), + ), ]; for (test, config) in tests { diff --git a/tests/src/glr/mod.rs b/tests/src/glr/mod.rs index 67750e51..f8bb058b 100644 --- a/tests/src/glr/mod.rs +++ b/tests/src/glr/mod.rs @@ -3,4 +3,5 @@ mod errors; mod evaluate; mod forest; mod lexical_ambiguity; +mod regressions; mod special; diff --git a/tests/src/glr/regressions/issue_16_subtract_overflow_panic/inline.rustemo b/tests/src/glr/regressions/issue_16_subtract_overflow_panic/inline.rustemo new file mode 100644 index 00000000..e1e7c004 --- /dev/null +++ b/tests/src/glr/regressions/issue_16_subtract_overflow_panic/inline.rustemo @@ -0,0 +1,43 @@ +Inline: InlineEl*; +InlineEl: prefix=StrongDelim children=Inline suffix=StrongDelim? {Strong, 11, left} + | prefix=EmphasisDelim children=Inline suffix=EmphasisDelim? {Emphasis, 11, left} + | title_prefix=LinkTitlePrefix title=Inline continuation=Link1? {Link , 11, left} + | prefix=CodeDelim text=CodeChar* suffix=CodeDelim? {Code, 11, left} + | text=TextChar+ {Text, 9, left}; + +StrongDelim: StrongT; + +EmphasisDelim: EmphasisT; + +LinkTitlePrefix: LinkTitlePrefixT; +LinkTitleSuffix: LinkTitleSuffixT; +LinkAddressPrefix: LinkAddressPrefixT; +LinkAddressSuffix: LinkAddressSuffixT; +Link1: title_suffix=LinkTitleSuffix address=LinkAddress?; +LinkAddress: prefix=LinkAddressPrefix address=LinkAddressChar* suffix=LinkAddressSuffix?; +LinkAddressChar: LinkAddressCharT | EscapedChar; + +CodeDelim: CodeDelimT; +CodeChar: CodeCharT | EscapedChar; + +TextChar: TextCharT | EscapedChar; + +EscapeChar: EscapeT; +EscapedChar: prefix=EscapeChar text=AnyCharT; + +Layout: Empty; + +terminals +Empty: ""; +EscapeT: "\\"; +AnyCharT: /./; +TextCharT: /[^*_`\\]/; +CodeDelimT: "`"; +CodeCharT: /[^`\\]/; +LinkTitlePrefixT: "["; +LinkTitleSuffixT: "]("; +LinkAddressPrefixT: "("; +LinkAddressSuffixT: ")"; +LinkAddressCharT: /[^)\\]/; +StrongT: "*"; +EmphasisT: "_"; \ No newline at end of file diff --git a/tests/src/glr/regressions/issue_16_subtract_overflow_panic/mod.rs b/tests/src/glr/regressions/issue_16_subtract_overflow_panic/mod.rs new file mode 100644 index 00000000..e4cdf401 --- /dev/null +++ b/tests/src/glr/regressions/issue_16_subtract_overflow_panic/mod.rs @@ -0,0 +1,22 @@ +use rustemo::{rustemo_mod, Parser}; + +rustemo_mod!( + inline, + "/src/glr/regressions/issue_16_subtract_overflow_panic" +); +rustemo_mod!( + inline_actions, + "/src/glr/regressions/issue_16_subtract_overflow_panic" +); + +use self::inline::{DefaultBuilder, InlineParser}; + +#[test] +fn subtract_overflow() { + InlineParser::new() + .parse("*ld 2") + .unwrap() + .get_first_tree() + .unwrap() + .build(&mut DefaultBuilder::new()); +} diff --git a/tests/src/glr/regressions/mod.rs b/tests/src/glr/regressions/mod.rs new file mode 100644 index 00000000..42d9b043 --- /dev/null +++ b/tests/src/glr/regressions/mod.rs @@ -0,0 +1 @@ +mod issue_16_subtract_overflow_panic;