shithub: mc

Download patch

ref: f14bc15334c9a8527544f7f4b1be3a700274e02a
parent: a2653e75140890d3b29c1ff9f3abc2c281bda1d7
author: Ori Bernstein <ori@markovcorp.com>
date: Thu Feb 1 06:53:34 EST 2018

Add test for bio skipto.

--- a/.gitignore
+++ b/.gitignore
@@ -31,5 +31,6 @@
 # test outputs
 *.log
 **/test/*
+!**/test/data/*
 !**/test/*.myr
 !**/test/runtest.sh
--- /dev/null
+++ b/lib/bio/test/bio-skipto.myr
@@ -1,0 +1,26 @@
+use std
+use bio
+
+const main = {
+	var buf : byte[16]
+	var f
+
+	/* use the expected write data as read data */
+	f = std.try(bio.open("data/bio-skipto", bio.Rd))
+
+	/* read bar from foobar */
+	bio.skipto(f, "foo")
+	bio.read(f, buf[:3])
+	std.assert(std.eq(buf[:3], "bar"), "did not read bar afer foo")
+
+	/* we're past foobar, read to eof */
+	bio.skipto(f, "foo")
+	match bio.read(f, buf[:3])
+	| `std.Err `bio.Eof:	/* ok */
+	| `std.Ok _:		std.fatal("expected EOF")
+	| `std.Err e:		std.fatal("expected EOF, got {}\n", e)
+	;;
+	
+	std.put("success: all reads matched\n")
+}
+
--- a/lib/bio/test/bld.sub
+++ b/lib/bio/test/bld.sub
@@ -56,3 +56,11 @@
 	lib @/lib/bio:bio
 ;;
 
+
+bin skipto {test} =
+	bio-skipto.myr
+	lib @/lib/std:std
+	lib @/lib/sys:sys
+	lib @/lib/bio:bio
+;;
+
--- /dev/null
+++ b/lib/bio/test/data/bio-skipto
@@ -1,0 +1,1 @@
+asdffoobarbaz