2018-04-02 15:04:42 +00:00
|
|
|
package vm_test
|
|
|
|
|
2019-08-20 17:37:06 +00:00
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
)
|
2018-02-19 09:24:28 +00:00
|
|
|
|
|
|
|
var assignTestCases = []testCase{
|
|
|
|
{
|
|
|
|
"chain define",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
y := x
|
|
|
|
z := y
|
|
|
|
foo := z
|
|
|
|
bar := foo
|
|
|
|
return bar
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(4),
|
2018-02-19 09:24:28 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"simple assign",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
x = 8
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(8),
|
2018-02-19 09:24:28 +00:00
|
|
|
},
|
2018-02-24 09:06:48 +00:00
|
|
|
{
|
|
|
|
"add assign",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
x += 8
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(12),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"sub assign",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
x -= 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(2),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"mul assign",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
x *= 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(8),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"div assign",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
x /= 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(2),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"add assign binary expr",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
x += 6 + 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(12),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"add assign binary expr ident",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
y := 5
|
|
|
|
x += 6 + y
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(15),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"decl assign",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
var x int = 4
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(4),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
2018-02-27 09:04:24 +00:00
|
|
|
{
|
|
|
|
"multi assign",
|
|
|
|
`
|
|
|
|
package foo
|
|
|
|
func Main() int {
|
|
|
|
x, y := 1, 2
|
|
|
|
return x + y
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(3),
|
2018-02-27 09:04:24 +00:00
|
|
|
},
|
2018-02-19 09:24:28 +00:00
|
|
|
}
|
2019-08-20 17:37:06 +00:00
|
|
|
|
|
|
|
func TestAssignments(t *testing.T) {
|
2019-10-18 15:36:54 +00:00
|
|
|
runTestCases(t, assignTestCases)
|
2019-08-20 17:37:06 +00:00
|
|
|
}
|