mirror of
https://github.com/vlang/v.git
synced 2025-09-16 16:02:29 +03:00
io.string_reader: fix needs_fill_until check (#21005)
This commit is contained in:
parent
8ec990eed8
commit
54da256b9f
2 changed files with 15 additions and 1 deletions
|
@ -52,7 +52,7 @@ pub fn (r StringReader) needs_fill() bool {
|
||||||
// needs_fill_until returns whether the buffer needs refilling in order to read
|
// needs_fill_until returns whether the buffer needs refilling in order to read
|
||||||
// `n` bytes
|
// `n` bytes
|
||||||
pub fn (r StringReader) needs_fill_until(n int) bool {
|
pub fn (r StringReader) needs_fill_until(n int) bool {
|
||||||
return r.offset + n >= r.builder.len
|
return r.offset + n > r.builder.len
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill_bufer tries to read data into the buffer until either a 0 length read or if read_to_end_of_stream
|
// fill_bufer tries to read data into the buffer until either a 0 length read or if read_to_end_of_stream
|
||||||
|
|
|
@ -89,6 +89,20 @@ fn test_from_string() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_from_string_read_byte_one_by_one() {
|
||||||
|
mut reader := StringReader.new(source: 'test')
|
||||||
|
assert reader.read_bytes(1)![0].ascii_str() == 't'
|
||||||
|
assert reader.read_bytes(1)![0].ascii_str() == 'e'
|
||||||
|
assert reader.read_bytes(1)![0].ascii_str() == 's'
|
||||||
|
assert reader.read_bytes(1)![0].ascii_str() == 't'
|
||||||
|
|
||||||
|
if _ := reader.read_all(false) {
|
||||||
|
assert false, 'should return Eof'
|
||||||
|
} else {
|
||||||
|
assert err is io.Eof
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn test_from_string_and_reader() {
|
fn test_from_string_and_reader() {
|
||||||
buf := Buf{
|
buf := Buf{
|
||||||
bytes: 'buffer'.bytes()
|
bytes: 'buffer'.bytes()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue