Add spec to test parsing lists
This commit is contained in:
parent
727c8cd1ea
commit
ad09ff039a
@ -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
spec/test_parsing_lists.d
Normal file
25
spec/test_parsing_lists.d
Normal 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);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user