github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/tests/tests.gno (about) 1 package tests 2 3 import ( 4 "std" 5 6 psubtests "gno.land/p/demo/tests/subtests" 7 "gno.land/r/demo/tests" 8 rtests "gno.land/r/demo/tests" 9 ) 10 11 const World = "world" 12 13 // IncCounter demonstrates that it's possible to call a realm function from 14 // a package. So a package can potentially write into the store, by calling 15 // an other realm. 16 func IncCounter() { 17 tests.IncCounter() 18 } 19 20 func CurrentRealmPath() string { 21 return std.CurrentRealmPath() 22 } 23 24 //---------------------------------------- 25 // cross realm test vars 26 27 type TestRealmObject2 struct { 28 Field string 29 } 30 31 func (o2 *TestRealmObject2) Modify() { 32 o2.Field = "modified" 33 } 34 35 var ( 36 somevalue1 TestRealmObject2 37 SomeValue2 TestRealmObject2 38 SomeValue3 *TestRealmObject2 39 ) 40 41 func init() { 42 somevalue1 = TestRealmObject2{Field: "init"} 43 SomeValue2 = TestRealmObject2{Field: "init"} 44 SomeValue3 = &TestRealmObject2{Field: "init"} 45 } 46 47 func ModifyTestRealmObject2a() { 48 somevalue1.Field = "modified" 49 } 50 51 func ModifyTestRealmObject2b() { 52 SomeValue2.Field = "modified" 53 } 54 55 func ModifyTestRealmObject2c() { 56 SomeValue3.Field = "modified" 57 } 58 59 func GetPrevRealm() std.Realm { 60 return std.PrevRealm() 61 } 62 63 func GetPSubtestsPrevRealm() std.Realm { 64 return psubtests.GetPrevRealm() 65 } 66 67 func GetRTestsGetPrevRealm() std.Realm { 68 return rtests.GetPrevRealm() 69 } 70 71 // Warning: unsafe pattern. 72 func Exec(fn func()) { 73 fn() 74 }