mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Add an optional offset to File.readBytes().
This commit is contained in:
@ -10,4 +10,10 @@ System.print(file.readBytes(7)) // expect: this is
|
||||
// Allows zero.
|
||||
System.print(file.readBytes(0).bytes.count) // expect: 0
|
||||
|
||||
// A longer number reads the whole file.
|
||||
System.print(file.readBytes(100)) // expect: this is a text file
|
||||
|
||||
// Reading past the end truncates the buffer.
|
||||
System.print(file.readBytes(100).bytes.count) // expect: 19
|
||||
|
||||
file.close()
|
||||
|
||||
20
test/io/file/read_bytes_from.wren
Normal file
20
test/io/file/read_bytes_from.wren
Normal file
@ -0,0 +1,20 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
|
||||
// Zero starts at the beginning.
|
||||
System.print(file.readBytes(3, 0)) // expect: thi
|
||||
|
||||
// Starts at the offset.
|
||||
System.print(file.readBytes(8, 3)) // expect: s is a t
|
||||
|
||||
// Allows zero.
|
||||
System.print(file.readBytes(0, 4).bytes.count) // expect: 0
|
||||
|
||||
// A longer number length reads until the end.
|
||||
System.print(file.readBytes(100, 2)) // expect: is is a text file
|
||||
|
||||
// An offset past the end returns an empty string.
|
||||
System.print(file.readBytes(100, 30).bytes.count) // expect: 0
|
||||
|
||||
file.close()
|
||||
6
test/io/file/read_bytes_from_after_close.wren
Normal file
6
test/io/file/read_bytes_from_after_close.wren
Normal file
@ -0,0 +1,6 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
file.close()
|
||||
|
||||
file.readBytes(3, 0) // expect runtime error: File is not open.
|
||||
4
test/io/file/read_bytes_from_count_negative.wren
Normal file
4
test/io/file/read_bytes_from_count_negative.wren
Normal file
@ -0,0 +1,4 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
file.readBytes(-1, 0) // expect runtime error: Count cannot be negative.
|
||||
4
test/io/file/read_bytes_from_count_not_integer.wren
Normal file
4
test/io/file/read_bytes_from_count_not_integer.wren
Normal file
@ -0,0 +1,4 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
file.readBytes(1.2, 0) // expect runtime error: Count must be an integer.
|
||||
4
test/io/file/read_bytes_from_count_not_num.wren
Normal file
4
test/io/file/read_bytes_from_count_not_num.wren
Normal file
@ -0,0 +1,4 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
file.readBytes("not num", 0) // expect runtime error: Count must be an integer.
|
||||
4
test/io/file/read_bytes_from_offset_negative.wren
Normal file
4
test/io/file/read_bytes_from_offset_negative.wren
Normal file
@ -0,0 +1,4 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
file.readBytes(1, -1) // expect runtime error: Offset cannot be negative.
|
||||
4
test/io/file/read_bytes_from_offset_not_integer.wren
Normal file
4
test/io/file/read_bytes_from_offset_not_integer.wren
Normal file
@ -0,0 +1,4 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
file.readBytes(1, 1.2) // expect runtime error: Offset must be an integer.
|
||||
4
test/io/file/read_bytes_from_offset_not_num.wren
Normal file
4
test/io/file/read_bytes_from_offset_not_num.wren
Normal file
@ -0,0 +1,4 @@
|
||||
import "io" for File
|
||||
|
||||
var file = File.open("test/io/file/file.txt")
|
||||
file.readBytes(1, "not num") // expect runtime error: Offset must be an integer.
|
||||
Reference in New Issue
Block a user