mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Make strings iterable over their code points.
I'm not sure why, but this also regresses perf: binary_trees - wren .......... 3290 0.30s 96.68% relative to baseline delta_blue - wren .......... 7948 0.13s 99.06% relative to baseline fib - wren .......... 3165 0.32s 95.90% relative to baseline for - wren .......... 8242 0.12s 96.00% relative to baseline method_call - wren .......... 5417 0.18s 78.74% relative to baseline Need to investigate.
This commit is contained in:
@ -4,6 +4,9 @@ IO.print(a.iterate(0)) // expect: 1
|
||||
IO.print(a.iterate(1)) // expect: 2
|
||||
IO.print(a.iterate(2)) // expect: 3
|
||||
IO.print(a.iterate(3)) // expect: false
|
||||
|
||||
// Out of bounds.
|
||||
IO.print(a.iterate(123)) // expect: false
|
||||
IO.print(a.iterate(-1)) // expect: false
|
||||
|
||||
// Nothing to iterate in an empty list.
|
||||
|
||||
16
test/string/iterate.wren
Normal file
16
test/string/iterate.wren
Normal file
@ -0,0 +1,16 @@
|
||||
var s = "abçd"
|
||||
IO.print(s.iterate(null)) // expect: 0
|
||||
IO.print(s.iterate(0)) // expect: 1
|
||||
IO.print(s.iterate(1)) // expect: 2
|
||||
// Skip 3 because that's the middle of the ç sequence.
|
||||
IO.print(s.iterate(2)) // expect: 4
|
||||
// Iterating from the middle of a UTF-8 sequence goes to the next one.
|
||||
IO.print(s.iterate(3)) // expect: 4
|
||||
IO.print(s.iterate(4)) // expect: false
|
||||
|
||||
// Out of bounds.
|
||||
IO.print(s.iterate(123)) // expect: false
|
||||
IO.print(s.iterate(-1)) // expect: false
|
||||
|
||||
// Nothing to iterate in an empty string.
|
||||
IO.print("".iterate(null)) // expect: false
|
||||
1
test/string/iterate_iterator_not_int.wren
Normal file
1
test/string/iterate_iterator_not_int.wren
Normal file
@ -0,0 +1 @@
|
||||
"s".iterate(1.5) // expect runtime error: Iterator must be an integer.
|
||||
1
test/string/iterate_iterator_not_num.wren
Normal file
1
test/string/iterate_iterator_not_num.wren
Normal file
@ -0,0 +1 @@
|
||||
"s".iterate("2") // expect runtime error: Iterator must be a number.
|
||||
7
test/string/iterator_value.wren
Normal file
7
test/string/iterator_value.wren
Normal file
@ -0,0 +1,7 @@
|
||||
var s = "abçd"
|
||||
IO.print(s.iteratorValue(0)) // expect: a
|
||||
IO.print(s.iteratorValue(1)) // expect: b
|
||||
IO.print(s.iteratorValue(2)) // expect: ç
|
||||
// Iterator value in middle of UTF sequence is an empty string.
|
||||
IO.print(s.iteratorValue(3) == "") // expect: true
|
||||
IO.print(s.iteratorValue(4)) // expect: d
|
||||
1
test/string/iterator_value_iterator_not_int.wren
Normal file
1
test/string/iterator_value_iterator_not_int.wren
Normal file
@ -0,0 +1 @@
|
||||
"s".iteratorValue(1.5) // expect runtime error: Iterator must be an integer.
|
||||
1
test/string/iterator_value_iterator_not_num.wren
Normal file
1
test/string/iterator_value_iterator_not_num.wren
Normal file
@ -0,0 +1 @@
|
||||
"s".iteratorValue("2") // expect runtime error: Iterator must be a number.
|
||||
1
test/string/iterator_value_iterator_too_large.wren
Normal file
1
test/string/iterator_value_iterator_too_large.wren
Normal file
@ -0,0 +1 @@
|
||||
"123".iteratorValue(4) // expect runtime error: Iterator out of bounds.
|
||||
1
test/string/iterator_value_iterator_too_small.wren
Normal file
1
test/string/iterator_value_iterator_too_small.wren
Normal file
@ -0,0 +1 @@
|
||||
"123".iteratorValue(-5) // expect runtime error: Iterator out of bounds.
|
||||
Reference in New Issue
Block a user