Skip to content

Commit

Permalink
add tests_foo cross-realm type storage test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Apr 13, 2022
1 parent 0bc96e1 commit 64ff50e
Show file tree
Hide file tree
Showing 3 changed files with 823 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/gno.land/r/tests/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tests

import (
"strconv"
)

type Stringer interface {
String() string
}

var stringers []Stringer

func AddStringer(str Stringer) {
// NOTE: this is ridiculous, a slice that will become too long
// eventually. Don't do this in production programs; use
// gno.land/p/avl or similar structures.
stringers = append(stringers, str)
}

func Render(path string) string {
res := ""
// NOTE: like the function above, this function too will eventually
// become too expensive to call.
for i, stringer := range stringers {
res += strconv.Itoa(i) + ": " + stringer.String() + "\n"
}
return res
}
19 changes: 19 additions & 0 deletions examples/gno.land/r/tests_foo/foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tests_foo

import (
"gno.land/r/tests"
)

// for testing gno.land/r/tests/interfaces.go

type FooStringer struct {
FieldA string
}

func (fs *FooStringer) String() string {
return "&FooStringer{" + fs.FieldA + "}"
}

func AddFooStringer(fa string) {
tests.AddStringer(&FooStringer{fa})
}
Loading

0 comments on commit 64ff50e

Please sign in to comment.