Add spec to test parsing lists

This commit is contained in:
Josh Holtrop 2022-10-13 05:02:05 -04:00
parent 727c8cd1ea
commit ad09ff039a
2 changed files with 46 additions and 0 deletions

View File

@ -252,4 +252,25 @@ EOF
"Start!",
])
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

25
spec/test_parsing_lists.d Normal file
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);
}