mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Get ranges working in string subscripts (again).
Now with UTF-8 hotness!
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var string = "abcde"
|
||||
IO.print(string[0..0]) // expect: a
|
||||
IO.print(string[1...1] == "") // expect: true
|
||||
@ -33,3 +32,16 @@ IO.print(string[3...-6]) // expect: dcba
|
||||
// An empty range at zero is allowed on an empty string.
|
||||
IO.print(""[0...0] == "") // expect: true
|
||||
IO.print(""[0..-1] == "") // expect: true
|
||||
|
||||
// Indexes by byte, not code point.
|
||||
//
|
||||
// Bytes: 11111
|
||||
// 012345678901234
|
||||
// Chars: sø mé ஃ thî ng
|
||||
IO.print("søméஃthîng"[0..3]) // expect: søm
|
||||
IO.print("søméஃthîng"[3...10]) // expect: méஃt
|
||||
|
||||
// Only includes sequences whose first byte is in the range.
|
||||
IO.print("søméஃthîng"[2..6]) // expect: méஃ
|
||||
IO.print("søméஃthîng"[2...6]) // expect: mé
|
||||
IO.print("søméஃthîng"[2...7]) // expect: méஃ
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "string"
|
||||
a[1.5..2] // expect runtime error: Range start must be an integer.
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "123"
|
||||
a[3..2] // expect runtime error: Range start out of bounds.
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "123"
|
||||
a[-4..2] // expect runtime error: Range start out of bounds.
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "123"
|
||||
a[1...4] // expect runtime error: Range end out of bounds.
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "123"
|
||||
a[0...-5] // expect runtime error: Range end out of bounds.
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "string"
|
||||
a[1..2.5] // expect runtime error: Range end must be an integer.
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "123"
|
||||
a[1..3] // expect runtime error: Range end out of bounds.
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
// skip: Range subscripts for strings don't handle UTF-8.
|
||||
var a = "123"
|
||||
a[0..-4] // expect runtime error: Range end out of bounds.
|
||||
|
||||
Reference in New Issue
Block a user