mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
io: make buffered_writer_test.v more robust
This commit is contained in:
parent
9bc975eb07
commit
e03bd3f803
@ -1,6 +1,10 @@
|
|||||||
import io
|
import io
|
||||||
import rand
|
import rand
|
||||||
|
|
||||||
|
fn small_amount() int {
|
||||||
|
return int(rand.u8()) + 1
|
||||||
|
}
|
||||||
|
|
||||||
struct ArrayWriter {
|
struct ArrayWriter {
|
||||||
pub mut:
|
pub mut:
|
||||||
result []u8
|
result []u8
|
||||||
@ -56,7 +60,7 @@ fn test_write() {
|
|||||||
written := write_random_data(mut aw, mut bw, 65536)!
|
written := write_random_data(mut aw, mut bw, 65536)!
|
||||||
|
|
||||||
// now exceed buffer capacity by a little
|
// now exceed buffer capacity by a little
|
||||||
little := rand.u8()
|
little := small_amount()
|
||||||
excess := bw.available() + little
|
excess := bw.available() + little
|
||||||
excess_data := rand.bytes(excess)!
|
excess_data := rand.bytes(excess)!
|
||||||
w := bw.write(excess_data)!
|
w := bw.write(excess_data)!
|
||||||
@ -70,7 +74,7 @@ fn test_write_big() {
|
|||||||
max := 65536
|
max := 65536
|
||||||
mut bw := io.new_buffered_writer(writer: aw, cap: max)!
|
mut bw := io.new_buffered_writer(writer: aw, cap: max)!
|
||||||
|
|
||||||
more_than_max := max + rand.u8()
|
more_than_max := max + small_amount()
|
||||||
big_source := rand.bytes(more_than_max)!
|
big_source := rand.bytes(more_than_max)!
|
||||||
w := bw.write(big_source)!
|
w := bw.write(big_source)!
|
||||||
assert w == more_than_max
|
assert w == more_than_max
|
||||||
|
Loading…
x
Reference in New Issue
Block a user