Better argument validation for core methods.
This commit is contained in:
@@ -23,10 +23,5 @@ var f = [1, 2, 3]
|
||||
f.removeAt(-1)
|
||||
IO.write(f) // expect: [1, 2]
|
||||
|
||||
// Out of bounds.
|
||||
// TODO: Signal error in better way.
|
||||
IO.write([1, 2, 3].removeAt(3)) // expect: null
|
||||
IO.write([1, 2, 3].removeAt(-4)) // expect: null
|
||||
|
||||
// Return the removed value.
|
||||
IO.write([3, 4, 5].removeAt(1)) // expect: 4
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(1.5) // expect runtime error: Index must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt("2") // expect runtime error: Index must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(4) // expect runtime error: Index out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(-5) // expect runtime error: Index out of bounds.
|
||||
@@ -10,16 +10,3 @@ IO.write(list[-4]) // expect: a
|
||||
IO.write(list[-3]) // expect: b
|
||||
IO.write(list[-2]) // expect: c
|
||||
IO.write(list[-1]) // expect: d
|
||||
|
||||
// Handle out of bounds.
|
||||
// TODO: Should halt the fiber or raise an error somehow.
|
||||
IO.write(list[4]) // expect: null
|
||||
IO.write(list[-5]) // expect: null
|
||||
|
||||
// Handle wrong argument type.
|
||||
// TODO: Should halt the fiber or raise an error somehow.
|
||||
IO.write(list[true]) // expect: null
|
||||
|
||||
// Handle non-integer index.
|
||||
// TODO: Should halt the fiber or raise an error somehow.
|
||||
IO.write(list[1.5]) // expect: null
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1.5] // expect runtime error: Subscript must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a["2"] // expect runtime error: Subscript must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1.5] = 1 // expect runtime error: Subscript must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a["2"] = 1 // expect runtime error: Subscript must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[4] = 1 // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[-5] = 1 // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[4] // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[-5] // expect runtime error: Subscript out of bounds.
|
||||
Reference in New Issue
Block a user