Search Apps Documentation Source Content File Folder Download Copy Actions Download

nestedpkg_test.gno

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