nestedpkg_test.gno

1.71 Kb ยท 73 lines
 1package tests
 2
 3import (
 4	"std"
 5	"testing"
 6)
 7
 8func TestNestedPkg(t *testing.T) {
 9	// direct child
10	cur := "gno.land/r/demo/tests/foo"
11	testing.SetRealm(std.NewCodeRealm(cur))
12	if !IsCallerSubPath() {
13		t.Errorf(cur + " should be a sub path")
14	}
15	if IsCallerParentPath() {
16		t.Errorf(cur + " should not be a parent path")
17	}
18	if !HasCallerSameNamespace() {
19		t.Errorf(cur + " should be from the same namespace")
20	}
21
22	// grand-grand-child
23	cur = "gno.land/r/demo/tests/foo/bar/baz"
24	testing.SetRealm(std.NewCodeRealm(cur))
25	if !IsCallerSubPath() {
26		t.Errorf(cur + " should be a sub path")
27	}
28	if IsCallerParentPath() {
29		t.Errorf(cur + " should not be a parent path")
30	}
31	if !HasCallerSameNamespace() {
32		t.Errorf(cur + " should be from the same namespace")
33	}
34
35	// direct parent
36	cur = "gno.land/r/demo"
37	testing.SetRealm(std.NewCodeRealm(cur))
38	if IsCallerSubPath() {
39		t.Errorf(cur + " should not be a sub path")
40	}
41	if !IsCallerParentPath() {
42		t.Errorf(cur + " should be a parent path")
43	}
44	if !HasCallerSameNamespace() {
45		t.Errorf(cur + " should be from the same namespace")
46	}
47
48	// fake parent (prefix)
49	cur = "gno.land/r/dem"
50	testing.SetRealm(std.NewCodeRealm(cur))
51	if IsCallerSubPath() {
52		t.Errorf(cur + " should not be a sub path")
53	}
54	if IsCallerParentPath() {
55		t.Errorf(cur + " should not be a parent path")
56	}
57	if HasCallerSameNamespace() {
58		t.Errorf(cur + " should not be from the same namespace")
59	}
60
61	// different namespace
62	cur = "gno.land/r/foo"
63	testing.SetRealm(std.NewCodeRealm(cur))
64	if IsCallerSubPath() {
65		t.Errorf(cur + " should not be a sub path")
66	}
67	if IsCallerParentPath() {
68		t.Errorf(cur + " should not be a parent path")
69	}
70	if HasCallerSameNamespace() {
71		t.Errorf(cur + " should not be from the same namespace")
72	}
73}