Skip to content

Commit

Permalink
handle additional append cases
Browse files Browse the repository at this point in the history
  • Loading branch information
deelawn committed Nov 15, 2023
1 parent 9c0c35a commit de2a233
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
22 changes: 19 additions & 3 deletions gno.land/cmd/gnoland/testdata/append.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ stdout OK!
gnokey maketx call -pkgpath gno.land/r/append -func Append -gas-fee 1000000ugnot -gas-wanted 2000000 -args '1' -broadcast -chainid=tendermint_test test1
stdout OK!

gnokey maketx call -pkgpath gno.land/r/append -func AppendNil -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!

# Call Append 2
gnokey maketx call -pkgpath gno.land/r/append -func Append -gas-fee 1000000ugnot -gas-wanted 2000000 -args '2' -broadcast -chainid=tendermint_test test1
stdout OK!
Expand Down Expand Up @@ -60,6 +63,10 @@ gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot
stdout '("2-3-42-70-100-" string)'
stdout OK!

gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args 'd' -broadcast -chainid=tendermint_test test1
stdout '("1-" string)'
stdout OK!

-- append.gno --
package append

Expand All @@ -69,7 +76,7 @@ import (

type T struct{ i int }

var a, b []T
var a, b, d []T
var c = []T{{i: 100}}


Expand Down Expand Up @@ -104,10 +111,19 @@ func ReassignC() {
c[0] = T{i: 200}
}

func AppendNil() {
d = append(d, a...)
}

func Render(path string) string {
source := a
if path == "d" {
source = d
}

var s string
for i:=0;i<len(a);i++{
s+=ufmt.Sprintf("%d-", a[i].i)
for i:=0;i<len(source);i++{
s+=ufmt.Sprintf("%d-", source[i].i)
}
return s
}
15 changes: 8 additions & 7 deletions gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ func UverseNode() *PackageNode {
// append(nil, *SliceValue) new list ---------
list := make([]TypedValue, argsl)
if 0 < argsl {
copy(
list[:argsl],
argsb.List[argso:argso+argsl])
for i := 0; i < argsl; i++ {
list[i] = argsb.List[argso+i].DeepCopy(m.Alloc, m.Store)
}
}
m.PushValue(TypedValue{
T: xt,
Expand Down Expand Up @@ -469,11 +469,12 @@ func UverseNode() *PackageNode {
return
} else {
// append(*SliceValue, *NativeValue) new list --------
list := make([]TypedValue, xvl+argsl)
listLen := xvl + argsl
list := make([]TypedValue, listLen)

Check warning on line 473 in gnovm/pkg/gnolang/uverse.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/uverse.go#L472-L473

Added lines #L472 - L473 were not covered by tests
if 0 < xvl {
copy(
list[:xvl],
xvb.List[xvo:xvo+xvl])
for i := 0; i < listLen; i++ {
list[i] = xvb.List[xvo+i].DeepCopy(m.Alloc, m.Store)
}

Check warning on line 477 in gnovm/pkg/gnolang/uverse.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/uverse.go#L475-L477

Added lines #L475 - L477 were not covered by tests
}
if 0 < argsl {
copyNativeToList(
Expand Down

0 comments on commit de2a233

Please sign in to comment.