Fix a bug where len() builtin does not take immutable array
This commit is contained in:
parent
4f222b1650
commit
c57a7f8f98
2 changed files with 10 additions and 0 deletions
|
@ -12,6 +12,8 @@ func builtinLen(args ...Object) (Object, error) {
|
|||
switch arg := args[0].(type) {
|
||||
case *Array:
|
||||
return &Int{Value: int64(len(arg.Value))}, nil
|
||||
case *ImmutableArray:
|
||||
return &Int{Value: int64(len(arg.Value))}, nil
|
||||
case *String:
|
||||
return &Int{Value: int64(len(arg.Value))}, nil
|
||||
case *Bytes:
|
||||
|
|
|
@ -10,6 +10,14 @@ func TestBuiltinFunction(t *testing.T) {
|
|||
expect(t, `out = len("")`, 0)
|
||||
expect(t, `out = len("four")`, 4)
|
||||
expect(t, `out = len("hello world")`, 11)
|
||||
expect(t, `out = len([])`, 0)
|
||||
expect(t, `out = len([1, 2, 3])`, 3)
|
||||
expect(t, `out = len({})`, 0)
|
||||
expect(t, `out = len({a:1, b:2})`, 2)
|
||||
expect(t, `out = len(immutable([]))`, 0)
|
||||
expect(t, `out = len(immutable([1, 2, 3]))`, 3)
|
||||
expect(t, `out = len(immutable({}))`, 0)
|
||||
expect(t, `out = len(immutable({a:1, b:2}))`, 2)
|
||||
expectError(t, `len(1)`)
|
||||
expectError(t, `len("one", "two")`)
|
||||
|
||||
|
|
Loading…
Reference in a new issue