neoneo-go/pkg/compiler/type_test.go
Evgenii Stratonikov 0629479560 compiler: support non-struct methods
There is no need to restrict ourselves just to structs.
2020-05-19 16:40:26 +03:00

39 lines
595 B
Go

package compiler_test
import (
"math/big"
"testing"
)
func TestCustomType(t *testing.T) {
src := `
package foo
type bar int
type specialString string
func Main() specialString {
var x bar
var str specialString
x = 10
str = "some short string"
if x == 10 {
return str
}
return "none"
}
`
eval(t, src, []byte("some short string"))
}
func TestCustomTypeMethods(t *testing.T) {
src := `package foo
type bar int
func (b bar) add(a bar) bar { return a + b }
func Main() bar {
var b bar
b = 10
return b.add(32)
}`
eval(t, src, big.NewInt(42))
}