2019-12-23 14:05:34 +00:00
|
|
|
package compiler_test
|
2018-05-06 06:03:26 +00:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestStringToByteConversion(t *testing.T) {
|
|
|
|
src := `
|
|
|
|
package foo
|
|
|
|
func Main() []byte {
|
|
|
|
b := []byte("foo")
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
`
|
|
|
|
eval(t, src, []byte("foo"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStringToByteAppend(t *testing.T) {
|
|
|
|
src := `
|
|
|
|
package foo
|
|
|
|
func Main() []byte {
|
|
|
|
b := []byte("foo")
|
|
|
|
c := []byte("bar")
|
|
|
|
e := append(b, c...)
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
`
|
|
|
|
eval(t, src, []byte("foobar"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestByteConversionInFunctionCall(t *testing.T) {
|
|
|
|
src := `
|
|
|
|
package foo
|
|
|
|
func Main() []byte {
|
|
|
|
b := []byte("foo")
|
|
|
|
return handle(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func handle(b []byte) []byte {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
`
|
|
|
|
eval(t, src, []byte("foo"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestByteConversionDirectlyInFunctionCall(t *testing.T) {
|
|
|
|
src := `
|
|
|
|
package foo
|
|
|
|
func Main() []byte {
|
|
|
|
return handle([]byte("foo"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func handle(b []byte) []byte {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
`
|
|
|
|
eval(t, src, []byte("foo"))
|
|
|
|
}
|