parse: show error on test failure
This commit is contained in:
parent
a9a72e8f1f
commit
1e5ed47497
2 changed files with 14 additions and 3 deletions
|
@ -13,6 +13,8 @@ use io;
|
|||
mkword("def")]),
|
||||
(`#t #f`, [true, false]),
|
||||
(`#\a #\space #\nul`, ['a', ' ', '\0']),
|
||||
(`"\x0a;" "\x2014;" "\x2f9f4;"`, ["\n", "—", "嶲"]),
|
||||
(`#\x #\x0a; #\x2014; #\x2f9f4;`, ['x', '\n', '—', '嶲']),
|
||||
];
|
||||
|
||||
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) {
|
||||
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)) {
|
||||
fmt::printfln("Case {}: {}", i, cases[i].0)!;
|
||||
|
|
|
@ -22,10 +22,10 @@ export fn strerror(err: error) const str = {
|
|||
match (err) {
|
||||
case let err: invalid =>
|
||||
return fmt::bsprintf(buf,
|
||||
"{}:{}: Invalid token found", err.0, err.1);
|
||||
"Invalid token found at {}:{}", err.0, err.1);
|
||||
case let err: unterminated =>
|
||||
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 =>
|
||||
return io::strerror(err);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue