feat: add validation to skip/take and rename split parameter for clarity
Add type and range checks to Sequence.skip() and Sequence.take() methods, aborting with "Count must be a non-negative integer." when count is not a non-negative integer. Rename split() parameter from 'delim' to 'delimiter' and update its error message from "Argument must be a non-empty string." to "Delimiter must be a non-empty string." for consistency. Remove old behavior allowing negative counts and add new test files for skip/take validation errors.
This commit is contained in:
@@ -15,14 +15,11 @@ var test = TestSequence.new().skip(0)
|
||||
System.print(test is Sequence) // expect: true
|
||||
System.print(test) // expect: instance of SkipSequence
|
||||
|
||||
// Skipping 0 changes nothing
|
||||
// Skipping 0 changes nothing.
|
||||
System.print(test.toList) // expect: [1, 2, 3]
|
||||
|
||||
// Skipping 1 works
|
||||
// Skipping 1 works.
|
||||
System.print(test.skip(1).toList) // expect: [2, 3]
|
||||
|
||||
// Skipping more than length of sequence produces empty list
|
||||
// Skipping more than length of sequence produces empty list.
|
||||
System.print(test.skip(4).isEmpty) // expect: true
|
||||
|
||||
// Skipping less than 0 changes nothing
|
||||
System.print(test.skip(-10).toList) // expect: [1, 2, 3]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].skip(-1) // expect runtime error: Count must be a non-negative integer.
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].skip(1.2) // expect runtime error: Count must be a non-negative integer.
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].skip("s") // expect runtime error: Count must be a non-negative integer.
|
||||
@@ -15,14 +15,11 @@ var test = TestSequence.new().take(3)
|
||||
System.print(test is Sequence) // expect: true
|
||||
System.print(test) // expect: instance of TakeSequence
|
||||
|
||||
// Taking 0 produces empty list
|
||||
// Taking 0 produces empty list.
|
||||
System.print(test.take(0).isEmpty) // expect: true
|
||||
|
||||
// Taking 1 works
|
||||
// Taking 1 works.
|
||||
System.print(test.take(1).toList) // expect: [1]
|
||||
|
||||
// Taking more than length of sequence produces whole sequence
|
||||
// Taking more than length of sequence produces whole sequence.
|
||||
System.print(test.take(4).toList) // expect: [1, 2, 3]
|
||||
|
||||
// Taking less than 0 produces empty list
|
||||
System.print(test.take(-10).isEmpty) // expect: true
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].take(-1) // expect runtime error: Count must be a non-negative integer.
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].take(1.2) // expect runtime error: Count must be a non-negative integer.
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].take("s") // expect runtime error: Count must be a non-negative integer.
|
||||
Reference in New Issue
Block a user