Better argument validation for core methods.
This commit is contained in:
@@ -4,5 +4,3 @@ IO.write("something".contains("meth")) // expect: true
|
||||
IO.write("something".contains("some")) // expect: true
|
||||
IO.write("something".contains("ing")) // expect: true
|
||||
IO.write("something".contains("math")) // expect: false
|
||||
|
||||
// TODO: Passing non-string as argument.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"foo".contains(1) // expect runtime error: Argument must be a string.
|
||||
@@ -9,16 +9,3 @@ IO.write("abcd"[-4]) // expect: a
|
||||
IO.write("abcd"[-3]) // expect: b
|
||||
IO.write("abcd"[-2]) // expect: c
|
||||
IO.write("abcd"[-1]) // expect: d
|
||||
|
||||
// Handle out of bounds.
|
||||
// TODO: Should halt the fiber or raise an error somehow.
|
||||
IO.write("abcd"[4]) // expect: null
|
||||
IO.write("abcd"[-5]) // expect: null
|
||||
|
||||
// Handle wrong argument type.
|
||||
// TODO: Should halt the fiber or raise an error somehow.
|
||||
IO.write("abcd"[true]) // expect: null
|
||||
|
||||
// Handle non-integer index.
|
||||
// TODO: Should halt the fiber or raise an error somehow.
|
||||
IO.write("abcd"[1.5]) // expect: null
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = "123"
|
||||
a[1.5] // expect runtime error: Subscript must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = "123"
|
||||
a["2"] // expect runtime error: Subscript must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = "123"
|
||||
a[4] // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = "123"
|
||||
a[-5] // expect runtime error: Subscript out of bounds.
|
||||
Reference in New Issue
Block a user