From ad09ff039a5513eda6a905ffad08ac3ba7c5e122 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 13 Oct 2022 05:02:05 -0400 Subject: [PATCH] Add spec to test parsing lists --- spec/propane_spec.rb | 21 +++++++++++++++++++++ spec/test_parsing_lists.d | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 spec/test_parsing_lists.d diff --git a/spec/propane_spec.rb b/spec/propane_spec.rb index 7a7077a..dc55ed9 100644 --- a/spec/propane_spec.rb +++ b/spec/propane_spec.rb @@ -252,4 +252,25 @@ EOF "Start!", ]) end + + it "parses lists" do + write_grammar < As << + $$ = $1; +>> +As -> << + $$ = 0u; +>> +As -> As a << + $$ = $1 + 1u; +>> +EOF + build_parser + compile("spec/test_parsing_lists.d") + results = run + expect(results.status).to eq 0 + expect(results.stderr).to eq "" + end end diff --git a/spec/test_parsing_lists.d b/spec/test_parsing_lists.d new file mode 100644 index 0000000..71df9e5 --- /dev/null +++ b/spec/test_parsing_lists.d @@ -0,0 +1,25 @@ +import testparser; +import std.stdio; + +int main() +{ + return 0; +} + +unittest +{ + string input = "a"; + auto parser = new Testparser.Parser(cast(const(ubyte) *)input.ptr, input.length); + assert(parser.parse() == true); + assert(parser.result == 1u); + + input = ""; + parser = new Testparser.Parser(cast(const(ubyte) *)input.ptr, input.length); + assert(parser.parse() == true); + assert(parser.result == 0u); + + input = "aaaaaaaaaaaaaaaa"; + parser = new Testparser.Parser(cast(const(ubyte) *)input.ptr, input.length); + assert(parser.parse() == true); + assert(parser.result == 16u); +}