xgo/runtime/vm_srcmod_test.go
Daniel 2f86800724
'enum' module (#166)
* 1. adding more methods to enum module
2. added ModuleMap.AddMap()
3. added bytes iterator

* add builtin functions 'is_enumerable' and 'is_array_like'

* builtin function 'is_iterable'

* first iteration on 'enum' module

* fix 'is_iterable' builtin function
2019-03-27 01:27:59 -07:00

49 lines
1.1 KiB
Go

package runtime_test
import "testing"
func TestSrcModEnum(t *testing.T) {
expect(t, `
x := import("enum")
out = x.all([1, 2, 3], func(_, v) { return v >= 1 })
`, Opts().Stdlib(), true)
expect(t, `
x := import("enum")
out = x.all([1, 2, 3], func(_, v) { return v >= 2 })
`, Opts().Stdlib(), false)
expect(t, `
x := import("enum")
out = x.any([1, 2, 3], func(_, v) { return v >= 1 })
`, Opts().Stdlib(), true)
expect(t, `
x := import("enum")
out = x.any([1, 2, 3], func(_, v) { return v >= 2 })
`, Opts().Stdlib(), true)
expect(t, `
x := import("enum")
out = x.chunk([1, 2, 3], 1)
`, Opts().Stdlib(), ARR{ARR{1}, ARR{2}, ARR{3}})
expect(t, `
x := import("enum")
out = x.chunk([1, 2, 3], 2)
`, Opts().Stdlib(), ARR{ARR{1, 2}, ARR{3}})
expect(t, `
x := import("enum")
out = x.chunk([1, 2, 3], 3)
`, Opts().Stdlib(), ARR{ARR{1, 2, 3}})
expect(t, `
x := import("enum")
out = x.chunk([1, 2, 3], 4)
`, Opts().Stdlib(), ARR{ARR{1, 2, 3}})
expect(t, `
x := import("enum")
out = x.chunk([1, 2, 3, 4, 5, 6], 2)
`, Opts().Stdlib(), ARR{ARR{1, 2}, ARR{3, 4}, ARR{5, 6}})
expect(t, `
x := import("enum")
out = x.at([1, 2, 3], 0)
`, Opts().Stdlib(), 1)
}