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-15 15:35:49 +00:00
|
|
|
|
|
|
|
var binaryExprTestCases = []testCase{
|
|
|
|
{
|
|
|
|
"simple add",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 2 + 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(4),
|
2018-02-15 15:35:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"simple sub",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 2 - 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(0),
|
2018-02-15 15:35:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"simple div",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 2 / 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(1),
|
2018-02-15 15:35:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"simple mul",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 4 * 2
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(8),
|
2018-02-15 15:35:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"simple binary expr in return",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 2
|
|
|
|
return 2 + x
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(4),
|
2018-02-15 15:35:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"complex binary expr",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 4
|
|
|
|
y := 8
|
|
|
|
z := x + 2 + 2 - 8
|
|
|
|
return y * z
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(0),
|
2018-02-15 15:35:49 +00:00
|
|
|
},
|
2018-02-24 09:06:48 +00:00
|
|
|
{
|
2019-08-20 17:43:43 +00:00
|
|
|
"compare not equal strings with eql",
|
2018-02-24 09:06:48 +00:00
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
str := "a string"
|
|
|
|
if str == "another string" {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(0),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-20 17:43:43 +00:00
|
|
|
"compare equal strings with eql",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
str := "a string"
|
|
|
|
if str == "a string" {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
big.NewInt(1),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"compare not equal strings with neq",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
str := "a string"
|
|
|
|
if str != "another string" {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
big.NewInt(1),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"compare equal strings with neq",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
str := "a string"
|
|
|
|
if str != "a string" {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
big.NewInt(0),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"compare equal ints with eql",
|
2018-02-24 09:06:48 +00:00
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 10
|
|
|
|
if x == 10 {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(1),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-20 17:43:43 +00:00
|
|
|
"compare equal ints with neq",
|
2018-02-24 09:06:48 +00:00
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 10
|
|
|
|
if x != 10 {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
2018-04-02 15:04:42 +00:00
|
|
|
big.NewInt(0),
|
2018-02-24 09:06:48 +00:00
|
|
|
},
|
2019-08-20 17:43:43 +00:00
|
|
|
{
|
|
|
|
"compare not equal ints with eql",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 11
|
|
|
|
if x == 10 {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
big.NewInt(0),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"compare not equal ints with neq",
|
|
|
|
`
|
|
|
|
package testcase
|
|
|
|
func Main() int {
|
|
|
|
x := 11
|
|
|
|
if x != 10 {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
big.NewInt(1),
|
|
|
|
},
|
2018-02-15 15:35:49 +00:00
|
|
|
}
|
2019-08-20 17:37:06 +00:00
|
|
|
|
|
|
|
func TestBinaryExprs(t *testing.T) {
|
|
|
|
run_testcases(t, binaryExprTestCases)
|
|
|
|
}
|