nestedpkg_test.gno

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