xgo/runtime/vm_bytes_test.go

19 lines
506 B
Go
Raw Normal View History

2019-01-18 12:43:46 +03:00
package runtime_test
import (
"testing"
"github.com/d5/tengo/objects"
2019-01-18 12:43:46 +03:00
)
func TestBytes(t *testing.T) {
expect(t, `out = bytes("Hello World!")`, nil, []byte("Hello World!"))
expect(t, `out = bytes("Hello") + bytes(" ") + bytes("World!")`, nil, []byte("Hello World!"))
2019-01-18 12:43:46 +03:00
// bytes[] -> int
expect(t, `out = bytes("abcde")[0]`, nil, 97)
expect(t, `out = bytes("abcde")[1]`, nil, 98)
expect(t, `out = bytes("abcde")[4]`, nil, 101)
expect(t, `out = bytes("abcde")[10]`, nil, objects.UndefinedValue)
2019-01-18 12:43:46 +03:00
}