mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
io: add a test for read_all (#6898)
This commit is contained in:
40
vlib/io/reader_test.v
Normal file
40
vlib/io/reader_test.v
Normal file
@@ -0,0 +1,40 @@
|
||||
module io
|
||||
|
||||
struct Buf {
|
||||
pub:
|
||||
bytes []byte
|
||||
mut:
|
||||
i int
|
||||
}
|
||||
|
||||
fn (mut b Buf) read(mut buf []byte) ?int {
|
||||
if !(b.i < b.bytes.len) {
|
||||
return eof
|
||||
}
|
||||
n := copy(buf, b.bytes[b.i..b.bytes.len])
|
||||
b.i += n
|
||||
return n
|
||||
}
|
||||
|
||||
fn test_read_all() {
|
||||
buf := Buf{
|
||||
bytes: '123'.repeat(10).bytes()
|
||||
}
|
||||
res := read_all(buf) or {
|
||||
assert false
|
||||
''.bytes()
|
||||
}
|
||||
assert res == '123'.repeat(10).bytes()
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: This test failed by a bug of read_all
|
||||
fn test_read_all_huge() {
|
||||
buf := Buf{bytes: "123".repeat(100000).bytes()}
|
||||
res := read_all(buf) or {
|
||||
assert false
|
||||
"".bytes()
|
||||
}
|
||||
assert res == "123".repeat(100000).bytes()
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user