commit 091f53764256466a567f69bcf149324d726b93ab
parent ab6106091df0ebaa3b6248bc9f4d472e36fae654
Author: Lou Woell <lou.woell@posteo.de>
Date:   Thu, 11 Sep 2025 14:39:35 +0200

More tests for locate

Diffstat:
Mcmd/harehelper/+test/locate_test.ha | 53++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/cmd/harehelper/+test/locate_test.ha b/cmd/harehelper/+test/locate_test.ha @@ -1,10 +1,12 @@ use dirs; +use fmt; use hare::lex; use hare::module; use hare::parse; use os; use strings; +def q = 1, w = 2; const s = 1, d = 2; fn loc_test_fn (in: str, out: lex::location) void = { @@ -24,13 +26,16 @@ fn loc_test_fn (in: str, out: lex::location) void = { match(locate_symbol(&ctx, id)) { case void => abort(); case let l: lex::location => + fmt::errorfln("path: {}, expected: {}", l.path, out.path)!; assert(strings::hassuffix(l.path, out.path)); + fmt::errorfln("line: {}, expected: {}", l.line, out.line)!; assert(l.line == out.line); + fmt::errorfln("col: {}, expected: {}", l.col, out.col)!; assert(l.col == out.col); }; }; -@test fn locate_stdlib() void = { +@test fn locate_stdlib_func() void = { loc_test_fn("os::stdout", lex::location { path = "stdfd.ha", line = 29, @@ -39,21 +44,47 @@ fn loc_test_fn (in: str, out: lex::location) void = { }); }; +@test fn locate_local_func() void = { + loc_test_fn("cmd::harehelper::loc_test_fn", lex::location { + path = "locate_test.ha", + line = 10, + col = 20, + ... + }); +}; + +@test fn locate_global_multiple1 () void = { + loc_test_fn("cmd::harehelper::s", lex::location { + path = "locate_test.ha", + line = 9, + col = 18, + ... + }); +}; -@test fn locate_multiple() void = { +@test fn locate_global_multiple2 () void = { loc_test_fn("cmd::harehelper::d", lex::location { path = "locate_test.ha", - line = 6, + line = 9, + col = 18, + ... + }); +}; + +@test fn locate_const_multiple1 () void = { + loc_test_fn("cmd::harehelper::q", lex::location { + path = "locate_test.ha", + line = 7, col = 13, ... }); }; -// @test fn locate_local() void = { -// loc_test_fn("cmd::harehelper::main", lex::location { -// path = "helper.ha", -// line = 45, -// col = 3, -// ... -// }); -// }; +@test fn locate_const_multiple2 () void = { + loc_test_fn("cmd::harehelper::w", lex::location { + path = "locate_test.ha", + line = 7, + col = 13, + ... + }); +};