aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/io/io_test.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/io/io_test.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/io/io_test.v')
-rw-r--r--v_windows/v/vlib/io/io_test.v41
1 files changed, 41 insertions, 0 deletions
diff --git a/v_windows/v/vlib/io/io_test.v b/v_windows/v/vlib/io/io_test.v
new file mode 100644
index 0000000..fca17c2
--- /dev/null
+++ b/v_windows/v/vlib/io/io_test.v
@@ -0,0 +1,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
+}