Better argument validation for core methods.

This commit is contained in:
Bob Nystrom
2014-01-03 10:47:26 -08:00
parent a89386b4e8
commit 058c2606b0
23 changed files with 58 additions and 87 deletions
-2
View File
@@ -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.
-13
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
var a = "123"
a[1.5] // expect runtime error: Subscript must be an integer.
+2
View File
@@ -0,0 +1,2 @@
var a = "123"
a["2"] // expect runtime error: Subscript must be a number.
+2
View File
@@ -0,0 +1,2 @@
var a = "123"
a[4] // expect runtime error: Subscript out of bounds.
+2
View File
@@ -0,0 +1,2 @@
var a = "123"
a[-5] // expect runtime error: Subscript out of bounds.