Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ltzmaxwell committed Jan 7, 2025
1 parent 7ae8646 commit 304e8e3
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 130 deletions.
27 changes: 0 additions & 27 deletions gnovm/tests/files/ptrmap_0.gno

This file was deleted.

26 changes: 13 additions & 13 deletions gnovm/tests/files/ptrmap_1.gno
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// PKGPATH: gno.land/r/ptr_map
package ptr_map

type Foo struct {
name string
}
var (
m = map[int]int{}
i = 0
)

var root *Foo
func AddToMap(value int) {
m[i] = value
}

var f = &Foo{name: "a"}
var f2 = &Foo{name: "a2"}
func GetFromMap() int {
return m[i]
}

func init() {
root = f // origin of root is set as f's
AddToMap(5)
}

func main() {
f.name = "b"
println(root == f)

root = f2 // root has new origin(and pointer value)
println(root == f2)
r := GetFromMap()
println(r == 5)
}

// Output:
// true
// true
29 changes: 7 additions & 22 deletions gnovm/tests/files/ptrmap_14.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,19 @@
package ptr_map

var (
m = map[*int]int{}
i = new(int)
m = map[*int]string{}
a = 0
ptr *int = &a // A pointer to an int
i1 **int = &ptr
)

func AddToMap(value int) {
m[i] = value
}

func GetFromMap() int {
return m[i]
}

func init() {
*i = 1
AddToMap(5)
m[*i1] = "first key"
}

// ----above is initialized and persisted before main is executed.

func main() {
r := GetFromMap()
println(r == 5)

*i = 2 // this changes TV, also Base of a pointer value
r = GetFromMap()
println(r == 5)
println(m[*i1]) // Output: first key
}

// Output:
// true
// true
// first key
31 changes: 10 additions & 21 deletions gnovm/tests/files/ptrmap_15.gno
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
// PKGPATH: gno.land/r/ptr_map
package ptr_map

var (
m = map[*int]int{}
i = new(int)
)

func AddToMap(value int) {
m[i] = value
type MyStruct struct {
Key *int
}

func GetFromMap() int {
j := *i
return m[&j]
}
var (
m = map[*int]string{}
i1 = MyStruct{Key: new(int)}
)

func init() {
*i = 1
AddToMap(5)
*i1.Key = 1 // Set the value of the pointer
m[i1.Key] = "first key"
}

func main() {
r := GetFromMap()
println(r == 5)

*i = 2
r = GetFromMap()
println(r == 5)
println(m[i1.Key]) // Output: first key
}

// Output:
// false
// false
// first key
2 changes: 1 addition & 1 deletion gnovm/tests/files/ptrmap_19.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func AddToMap(value int) {
}

func GetFromMap() int {
i := 0 // same name and value path(3, 1), but different `origin`
i := 0
{
{
return m[&i]
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/ptrmap_23.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/ptr_map
package ptr_map

var arr = [2]int{1, 2} // Take the address of the array variable
var arr = [2]int{1, 2}
var m = map[*[2]int]string{}

func init() {
Expand Down
23 changes: 0 additions & 23 deletions gnovm/tests/files/ptrmap_27.gno

This file was deleted.

20 changes: 0 additions & 20 deletions gnovm/tests/files/ptrmap_28.gno

This file was deleted.

1 change: 0 additions & 1 deletion gnovm/tests/files/ptrmap_4.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func main() {
newArr := append(sArr[:1], sArr[2:]...) // same base array

// Compare pointers directly
//println(sArr[1] == newArr[1])
println(m[sArr[1]] == m[newArr[1]])
println(m[sArr[1]] == "")
println(m[newArr[1]] == "")
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/ptrmap_6.gno
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {

newArr = append(newArr, &S{4})
newArr = append(newArr, &S{5})
newArr = append(newArr, &S{6}) // reallocate array, inherit abs from last underlying array
newArr = append(newArr, &S{6}) // reallocate array

// Compare pointers directly
println(sArr[1] == newArr[1])
Expand Down

0 comments on commit 304e8e3

Please sign in to comment.