1
0
forked from Mirror/wren

Get ranges working in string subscripts (again).

Now with UTF-8 hotness!
This commit is contained in:
Bob Nystrom
2015-09-01 22:14:55 -07:00
parent 2e83f056c1
commit 783a5b750a
15 changed files with 96 additions and 51 deletions

View File

@ -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éஃ

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.