parse: show error on test failure

This commit is contained in:
Lobo Torres 2024-12-05 13:43:31 -03:00
parent a9a72e8f1f
commit 1e5ed47497
2 changed files with 14 additions and 3 deletions

View file

@ -13,6 +13,8 @@ use io;
mkword("def")]), mkword("def")]),
(`#t #f`, [true, false]), (`#t #f`, [true, false]),
(`#\a #\space #\nul`, ['a', ' ', '\0']), (`#\a #\space #\nul`, ['a', ' ', '\0']),
(`"\x0a;" "\x2014;" "\x2f9f4;"`, ["\n", "", "嶲"]),
(`#\x #\x0a; #\x2014; #\x2f9f4;`, ['x', '\n', '—', '嶲']),
]; ];
for (let i = 0z; i < len(cases); i += 1) { for (let i = 0z; i < len(cases); i += 1) {
@ -23,7 +25,16 @@ use io;
for (let j = 0z; j < len(cases[i].1); j += 1) { for (let j = 0z; j < len(cases[i].1); j += 1) {
const want = cases[i].1[j]; const want = cases[i].1[j];
const have = lex(&lexer)! as token; const have = match (lex(&lexer)) {
case let tok: token =>
yield tok;
case io::EOF =>
assert(false, "reached EOF");
return;
case let err: error =>
assert(false, strerror(err));
return;
};
if (!tokeq(want, have)) { if (!tokeq(want, have)) {
fmt::printfln("Case {}: {}", i, cases[i].0)!; fmt::printfln("Case {}: {}", i, cases[i].0)!;

View file

@ -22,10 +22,10 @@ export fn strerror(err: error) const str = {
match (err) { match (err) {
case let err: invalid => case let err: invalid =>
return fmt::bsprintf(buf, return fmt::bsprintf(buf,
"{}:{}: Invalid token found", err.0, err.1); "Invalid token found at {}:{}", err.0, err.1);
case let err: unterminated => case let err: unterminated =>
return fmt::bsprintf(buf, return fmt::bsprintf(buf,
"{}:{}: Unterminated {} found", err.1, err.2, err.0); "Unterminated {} found at {}:{}", err.0, err.1, err.2);
case let err: io::error => case let err: io::error =>
return io::strerror(err); return io::strerror(err);
}; };