compiler: support nil checks

This commit is contained in:
Roman Khimov 2020-06-24 08:57:04 +03:00
parent 6f5a42facf
commit 954c8ff8d6
2 changed files with 75 additions and 2 deletions

View file

@ -0,0 +1,55 @@
package compiler_test
import (
"math/big"
"testing"
)
var nilTestCases = []testCase{
{
"nil check positive right",
`
package foo
func Main() int {
var t interface{}
if t == nil {
return 1
}
return 2
}
`,
big.NewInt(1),
},
{
"nil check negative right",
`
package foo
func Main() int {
t := []byte{}
if t == nil {
return 1
}
return 2
}
`,
big.NewInt(2),
},
{
"nil check positive left",
`
package foo
func Main() int {
var t interface{}
if nil == t {
return 1
}
return 2
}
`,
big.NewInt(1),
},
}
func TestNil(t *testing.T) {
runTestCases(t, nilTestCases)
}