aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/io/multi_writer_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/multi_writer_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/multi_writer_test.v')
-rw-r--r--v_windows/v/vlib/io/multi_writer_test.v66
1 files changed, 66 insertions, 0 deletions
diff --git a/v_windows/v/vlib/io/multi_writer_test.v b/v_windows/v/vlib/io/multi_writer_test.v
new file mode 100644
index 0000000..2e317e8
--- /dev/null
+++ b/v_windows/v/vlib/io/multi_writer_test.v
@@ -0,0 +1,66 @@
+module io
+
+fn test_multi_writer_write_successful() {
+ w0 := TestWriter{}
+ w1 := TestWriter{}
+ mut mw := new_multi_writer(w0, w1)
+ n := mw.write('0123456789'.bytes()) or {
+ assert false
+ return
+ }
+ assert n == 10
+ assert w0.bytes == '0123456789'.bytes()
+ assert w1.bytes == '0123456789'.bytes()
+}
+
+fn test_multi_writer_write_incomplete() {
+ w0 := TestWriter{}
+ w1 := TestIncompleteWriter{}
+ mut mw := new_multi_writer(w0, w1)
+ n := mw.write('0123456789'.bytes()) or {
+ assert w0.bytes == '0123456789'.bytes()
+ assert w1.bytes == '012345678'.bytes()
+ return
+ }
+ assert false
+}
+
+fn test_multi_writer_write_error() {
+ w0 := TestWriter{}
+ w1 := TestErrorWriter{}
+ w2 := TestWriter{}
+ mut mw := new_multi_writer(w0, w1, w2)
+ n := mw.write('0123456789'.bytes()) or {
+ assert w0.bytes == '0123456789'.bytes()
+ assert w2.bytes == []
+ return
+ }
+ assert false
+}
+
+struct TestWriter {
+pub mut:
+ bytes []byte
+}
+
+fn (mut w TestWriter) write(buf []byte) ?int {
+ w.bytes << buf
+ return buf.len
+}
+
+struct TestIncompleteWriter {
+pub mut:
+ bytes []byte
+}
+
+fn (mut w TestIncompleteWriter) write(buf []byte) ?int {
+ b := buf[..buf.len - 1]
+ w.bytes << b
+ return b.len
+}
+
+struct TestErrorWriter {}
+
+fn (mut w TestErrorWriter) write(buf []byte) ?int {
+ return error('error writer errored')
+}