Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

tests.gno

1.80 Kb · 83 lines
 1package tests
 2
 3import (
 4	"chain/runtime"
 5	"chain/runtime/unsafe"
 6
 7	psubtests "gno.land/p/demo/tests/subtests/v0"
 8)
 9
10const World = "world"
11
12func CurrentRealmPath() string {
13	return unsafe.CurrentRealm().PkgPath()
14}
15
16//----------------------------------------
17// cross realm test vars
18
19type TestRealmObject2 struct {
20	Field string
21}
22
23func (o2 *TestRealmObject2) Modify() {
24	o2.Field = "modified"
25}
26
27// Value-receiver mutator. By Go/Gno semantics this only mutates the
28// method's local copy. Used by readonly-taint filetests to probe
29// whether a receiver carrying the sticky N_Readonly bit propagates
30// the bit onto the method-frame copy.
31func (o2 TestRealmObject2) ModifyVal() {
32	o2.Field = "modified-val"
33}
34
35// Unexported mutator. Used by the method-expression visibility filetest:
36// `(*tests.TestRealmObject2).clearField` from outside this package must
37// be rejected at preprocess time.
38func (o2 *TestRealmObject2) clearField() {
39	o2.Field = ""
40}
41
42var (
43	somevalue1 TestRealmObject2
44	SomeValue2 TestRealmObject2
45	SomeValue3 *TestRealmObject2
46)
47
48func init() {
49	somevalue1 = TestRealmObject2{Field: "init"}
50	SomeValue2 = TestRealmObject2{Field: "init"}
51	SomeValue3 = &TestRealmObject2{Field: "init"}
52}
53
54func ModifyTestRealmObject2a() {
55	somevalue1.Field = "modified"
56}
57
58func ModifyTestRealmObject2b() {
59	SomeValue2.Field = "modified"
60}
61
62func ModifyTestRealmObject2c() {
63	SomeValue3.Field = "modified"
64}
65
66func GetPreviousRealm() runtime.Realm {
67	return unsafe.PreviousRealm()
68}
69
70func GetPSubtestsPreviousRealm() runtime.Realm {
71	return psubtests.GetPreviousRealm()
72}
73
74// Warning: unsafe pattern.
75func Exec(fn func()) {
76	fn()
77}
78
79// ExecRlm mirrors Exec but threads the caller's rlm into the callback
80// so the callback can use `cross(rlm)` instead of bare `cross`.
81func ExecRlm(_ int, rlm realm, fn func(_ int, rlm realm)) {
82	fn(0, rlm)
83}