2019-12-23 14:05:34 +00:00
|
|
|
package compiler_test
|
2018-04-22 18:11:37 +00:00
|
|
|
|
2020-05-19 13:04:41 +00:00
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
)
|
2018-04-22 18:11:37 +00:00
|
|
|
|
|
|
|
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"))
|
|
|
|
}
|
2020-05-19 13:04:41 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|