1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/io/reader_test.v
2020-11-23 16:17:39 +01:00

41 lines
615 B
V

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()
}
*/