commit e9cdde89b2c3c68b7eedef9b3998df23069b2600
parent 73880ef86f21fd9a8da10cf967c87254d1c3857d
Author: Lou Woell <lou.woell@posteo.de>
Date: Fri, 19 Sep 2025 04:06:31 +0200
[locate] properly handle tag dirs, add tests
Diffstat:
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/cmd/harehelper/+test/locate_test.ha b/cmd/harehelper/+test/locate_test.ha
@@ -55,7 +55,7 @@ fn loc_test_fn (in: str, out: lex::location) void = {
});
};
-@test fn locate_local_func() void = {
+@test fn locate_local_tag_from_root() void = {
loc_test_fn("cmd::harehelper::loc_test_fn", lex::location {
path = "locate_test.ha",
line = 11,
@@ -64,6 +64,15 @@ fn loc_test_fn (in: str, out: lex::location) void = {
});
};
+@test fn locate_local_from_root() void = {
+ loc_test_fn("cmd::harehelper::locate", lex::location {
+ path = "locate.ha",
+ line = 23,
+ col = 13,
+ ...
+ });
+};
+
@test fn locate_global_multiple1 () void = {
loc_test_fn("cmd::harehelper::s", lex::location {
path = "locate_test.ha",
@@ -117,3 +126,43 @@ fn loc_test_fn (in: str, out: lex::location) void = {
...
});
};
+
+@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 = 11,
+ col = 20,
+ ...
+ });
+};
+
+@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 = 11,
+ col = 20,
+ ...
+ });
+};
+
+@test fn locate_local_from_base() void = {
+ os::chdir("./cmd/harehelper")!;
+ loc_test_fn("locate", lex::location {
+ path = "locate.ha",
+ line = 23,
+ col = 13,
+ ...
+ });
+};
+
+@test fn locate_local_from_tag() void = {
+ os::chdir("./cmd/harehelper/+test")!;
+ loc_test_fn("locate", lex::location {
+ path = "locate.ha",
+ line = 23,
+ col = 13,
+ ...
+ });
+};
diff --git a/cmd/harehelper/locate.ha b/cmd/harehelper/locate.ha
@@ -80,6 +80,9 @@ fn locate_symbol (
// if no namespace prefix is present look for a declaration in the cwd.
if (len(id) <= 1) {
let p = path::init(os::getcwd())!;
+ if (strings::hasprefix(path::peek(&p) as str, '+')) {
+ path::pop(&p);
+ };
ns = &p;
};