commit c8678714d48058c85a7da33297a03d7fdaea1670
parent a49c48e241b52cba807cb6b59dcde4effe12b505
Author: Lou Woell <lou.woell@posteo.de>
Date: Tue, 17 Feb 2026 05:50:43 +0100
[locate] refactor tests
Diffstat:
1 file changed, 60 insertions(+), 102 deletions(-)
diff --git a/cmd/harehelper/+test/locate_test.ha b/cmd/harehelper/+test/locate_test.ha
@@ -43,6 +43,49 @@ fn loc_test_fn (in: str, out: lex::location) void = {
};
};
+
+let os_loc = lex::location {
+ path = "os",
+ line = 0,
+ col = 0,
+ ...
+};
+
+let parse_loc = lex::location {
+ path = "parse",
+ line = 0,
+ col = 0,
+ ...
+};
+
+let loc_test_loc = lex::location {
+ path = "locate_test.ha",
+ line = 16,
+ col = 1,
+ ...
+};
+
+let locate_loc = lex::location {
+ path = "locate.ha",
+ line = 25,
+ col = 1,
+ ...
+};
+
+let type_loc = lex::location {
+ path = "type.ha",
+ line = 10,
+ col = 1,
+ ...
+};
+
+let fake_loc = lex::location {
+ path = "foo.ha",
+ line = 111,
+ col = 111,
+ ...
+};
+
@test fn locate_stdlib_var() void = {
loc_test_fn("os::stdout", lex::location {
path = "stdfd.ha",
@@ -53,163 +96,78 @@ fn loc_test_fn (in: str, out: lex::location) void = {
};
@test fn locate_local_tag_from_root() void = {
- loc_test_fn("cmd::harehelper::loc_test_fn", lex::location {
- path = "locate_test.ha",
- line = 16,
- col = 1,
- ...
- });
+ loc_test_fn("cmd::harehelper::loc_test_fn", loc_test_loc);
};
@test fn locate_local_from_root() void = {
- loc_test_fn("cmd::harehelper::locate", lex::location {
- path = "locate.ha",
- line = 25,
- col = 1,
- ...
- });
+ loc_test_fn("cmd::harehelper::locate", locate_loc);
};
@test fn locate_module () void = {
- loc_test_fn("os", lex::location {
- path = "os",
- line = 0,
- col = 0,
- ...
- });
+ loc_test_fn("os", os_loc);
};
@test fn locate_module_cwd () void = {
os::chdir("./cmd/harehelper/")!;
- loc_test_fn("os", lex::location {
- path = "os",
- line = 0,
- col = 0,
- ...
- });
+ loc_test_fn("os", os_loc);
};
@test fn locate_module_trailing () void = {
- loc_test_fn("os::", lex::location {
- path = "os",
- line = 0,
- col = 0,
- ...
- });
+ loc_test_fn("os::", os_loc);
};
@test fn locate_local_tag_from_tag() void = {
os::chdir("./cmd/harehelper/+test")!;
- loc_test_fn("loc_test_fn", lex::location {
- path = "locate_test.ha",
- line = 16,
- col = 1,
- ...
- });
+ loc_test_fn("loc_test_fn", loc_test_loc);
};
@test fn locate_local_tag_from_base() void = {
os::chdir("./cmd/harehelper")!;
- loc_test_fn("loc_test_fn", lex::location {
- path = "locate_test.ha",
- line = 16,
- col = 1,
- ...
- });
+ loc_test_fn("loc_test_fn", loc_test_loc);
};
@test fn locate_submodule () void = {
- loc_test_fn("hare::parse", lex::location {
- path = "parse",
- line = 0,
- col = 0,
- ...
- });
+ loc_test_fn("hare::parse", parse_loc);
};
@test fn locate_submodule_cwd () void = {
os::chdir("./cmd/harehelper/")!;
- loc_test_fn("hare::parse", lex::location {
- path = "parse",
- line = 0,
- col = 0,
- ...
- });
+ loc_test_fn("hare::parse", parse_loc);
};
@test fn locate_local_from_base() void = {
os::chdir("./cmd/harehelper")!;
- loc_test_fn("locate", lex::location {
- path = "locate.ha",
- line = 25,
- col = 1,
- ...
- });
+ loc_test_fn("locate", locate_loc);
};
@test fn locate_local_from_tag() void = {
os::chdir("./cmd/harehelper/+test")!;
- loc_test_fn("locate", lex::location {
- path = "locate.ha",
- line = 25,
- col = 1,
- ...
- });
+ loc_test_fn("locate", locate_loc);
};
@test fn locate_not_found() void = {
test::expectabort();
- loc_test_fn("nothing", lex::location {
- path = "foo.ha",
- line = 111,
- col = 111,
- ...
- });
+ loc_test_fn("nothing", fake_loc);
};
@test fn locate_not_found_module() void = {
test::expectabort();
- loc_test_fn("hare::nothing", lex::location {
- path = "foo.ha",
- line = 111,
- col = 111,
- ...
- });
+ loc_test_fn("hare::nothing", fake_loc);
};
@test fn locate_enum() void = {
- loc_test_fn("hare::ast::builtin_type", lex::location {
- path = "type.ha",
- line = 10,
- col = 1,
- ...
- });
+ loc_test_fn("hare::ast::builtin_type", type_loc);
};
@test fn locate_enum_member() void = {
- loc_test_fn("hare::ast::builtin_type", lex::location {
- path = "type.ha",
- line = 10,
- col = 1,
- ...
- });
+ loc_test_fn("hare::ast::builtin_type", type_loc);
};
@test fn locate_enum_member_nonexisting() void = {
- loc_test_fn("hare::ast::builtin_type::lou", lex::location {
- path = "type.ha",
- line = 10,
- col = 1,
- ...
- });
+ loc_test_fn("hare::ast::builtin_type::lou", type_loc);
};
@test fn locate_enum_nonexisting() void = {
test::expectabort();
- loc_test_fn("hare::ast::lou::lou", lex::location {
- path = "type.ha",
- line = 10,
- col = 1,
- ...
- });
+ loc_test_fn("hare::ast::lou::lou", type_loc);
};