forked from Mirror/wren
More stuff for working with strings and bytes!
- "\x" escape sequence to put byte values in strings: "\x34" - String.byteAt(index) gets value of byte in string. - String.bytes returns a raw sequence of bytes for a string. - String.codePointAt(index) gets the code point at an offset as a raw number.
This commit is contained in:
12
test/language/string/byte_escapes.wren
Normal file
12
test/language/string/byte_escapes.wren
Normal file
@ -0,0 +1,12 @@
|
||||
var s = "\x00\x12\x34\x56\x78\xab\xCD\xfFf"
|
||||
|
||||
IO.print(s.byteAt(0)) // expect: 0
|
||||
IO.print(s.byteAt(1)) // expect: 18
|
||||
IO.print(s.byteAt(2)) // expect: 52
|
||||
IO.print(s.byteAt(3)) // expect: 86
|
||||
IO.print(s.byteAt(4)) // expect: 120
|
||||
IO.print(s.byteAt(5)) // expect: 171
|
||||
IO.print(s.byteAt(6)) // expect: 205
|
||||
IO.print(s.byteAt(7)) // expect: 255
|
||||
// "f".
|
||||
IO.print(s.byteAt(8)) // expect: 102
|
||||
2
test/language/string/incomplete_byte_escape.wren
Normal file
2
test/language/string/incomplete_byte_escape.wren
Normal file
@ -0,0 +1,2 @@
|
||||
// expect error line 2
|
||||
"\x0"
|
||||
2
test/language/string/incomplete_byte_escape_at_eof.wren
Normal file
2
test/language/string/incomplete_byte_escape_at_eof.wren
Normal file
@ -0,0 +1,2 @@
|
||||
// expect error line 2
|
||||
"\x0
|
||||
2
test/language/string/invalid_byte_escape.wren
Normal file
2
test/language/string/invalid_byte_escape.wren
Normal file
@ -0,0 +1,2 @@
|
||||
// expect error line 2
|
||||
"\x0!"
|
||||
Reference in New Issue
Block a user