aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/vlib/io/io_test.v
blob: fca17c2d0398c3a80b8e7b86a8e50f5b3ceb107b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import io

struct Buf {
pub:
	bytes []byte
mut:
	i int
}

struct Writ {
pub mut:
	bytes []byte
}

fn (mut b Buf) read(mut buf []byte) ?int {
	if !(b.i < b.bytes.len) {
		return none
	}
	n := copy(buf, b.bytes[b.i..])
	b.i += n
	return n
}

fn (mut w Writ) write(buf []byte) ?int {
	if buf.len <= 0 {
		return none
	}
	w.bytes << buf
	return buf.len
}

fn test_copy() {
	src := Buf{
		bytes: 'abcdefghij'.repeat(10).bytes()
	}
	mut dst := Writ{
		bytes: []byte{}
	}
	io.cp(src, mut dst) or { assert false }
	assert dst.bytes == src.bytes
}