From 1e5ed474976e2f55ca54782b1c789bd841e4a2ef Mon Sep 17 00:00:00 2001 From: Lobo Torres Date: Thu, 5 Dec 2024 13:43:31 -0300 Subject: [PATCH] parse: show error on test failure --- parse/+test/lexer.ha | 13 ++++++++++++- parse/types.ha | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/parse/+test/lexer.ha b/parse/+test/lexer.ha index bd2d359..5c883cf 100644 --- a/parse/+test/lexer.ha +++ b/parse/+test/lexer.ha @@ -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)!; diff --git a/parse/types.ha b/parse/types.ha index b94c5c6..809ed7e 100644 --- a/parse/types.ha +++ b/parse/types.ha @@ -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); };