commit b69b8447865c176137271554c06656fa298615df
parent 2d9dc502568d9fd07e87713fa3c8b7d05e294e8d
Author: Lou Woell <lou.woell@posteo.de>
Date: Wed, 10 Sep 2025 19:04:20 +0200
add tests for namespace resolver
Diffstat:
1 file changed, 67 insertions(+), 0 deletions(-)
diff --git a/cmd/harehelper/+test/resolve_test.ha b/cmd/harehelper/+test/resolve_test.ha
@@ -0,0 +1,67 @@
+use hare::module::*;
+use hare::parse;
+use hare::ast;
+use os;
+use memio::{concat, dynamic};
+use dirs;
+use m = math;
+
+fn test_fn (in: str, out: str) void = {
+ const ctx = context {
+ harepath = os::tryenv("HAREPATH", HAREPATH),
+ harecache = match (os::getenv("HARECACHE")) {
+ case let s: str =>
+ yield s;
+ case void =>
+ yield dirs::cache("hare");
+ },
+ tags = ["linux"],
+ };
+
+ const id = parse::identstr(in)!;
+ const exp = parse::identstr(out)!;
+
+ const res = find_uid(&ctx, id, "./cmd/harehelper/+test/resolve_test.ha");
+
+ match(res) {
+ case void => abort();
+ case let i: ast::ident =>
+ if(!ast::ident_eq(i, exp)) abort();
+ };
+};
+
+@test fn resolve_wildcard_intern () void = {
+ test_fn("context", "hare::module::context");
+};
+
+@test fn resolve_wildcard_module () void = {
+ test_fn("hare::module", "hare::module");
+};
+
+@test fn resolve_member_intern () void = {
+ test_fn("dynamic", "memio::dynamic");
+};
+
+@test fn resolve_member_module () void = {
+ test_fn("memio", "memio");
+};
+
+@test fn resolve_module_noimport () void = {
+ test_fn("bufio", "bufio");
+};
+
+@test fn resolve_symbol_noimport () void = {
+ test_fn("bufio::finish", "bufio::finish");
+};
+
+@test fn resolve_symbol_import () void = {
+ test_fn("parse::identstr", "hare::parse::identstr");
+};
+
+@test fn resolve_alias_symbol () void = {
+ test_fn("m::absi", "math::absi");
+};
+
+@test fn resolve_alias_module () void = {
+ test_fn("m", "math");
+};