Add spec to test parsing lists

This commit is contained in:
josh committed 2022-10-13 05:02:05 -04:00
1 parent 727c8cd1ea
commit ad09ff039a
2 files changed
+46

No files matched your search

+21
View File
@@ -252,4 +252,25 @@ EOF
"Start!", "Start!",
]) ])
end end
it "parses lists" do
write_grammar <<EOF
result_type uint;
token a;
Start -> 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 end
+25
View File
@@ -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);
}