shithub: mc

Download patch

ref: c505373d1bbcad1e7861f6db054eddcfd5cac354
parent: b88dc2174f25b7ca08a0a7bc42bf981488de54c9
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 11 16:48:28 EDT 2017

Add memfiles.

--- a/lib/bio/bld.sub
+++ b/lib/bio/bld.sub
@@ -3,6 +3,7 @@
 	geti.myr
 	puti.myr
 	iter.myr
+	mem.myr
 
         lib ../std:std
         lib ../sys:sys
--- /dev/null
+++ b/lib/bio/test/mem.myr
@@ -1,0 +1,30 @@
+use std
+use bio
+
+const main = {
+	var f
+	var buf : byte[16]
+
+	f = bio.mkmem("hello world")
+	match bio.read(f, buf[:3])
+	| `bio.Ok "hel":
+		/* ok */
+	| _:
+		std.fatal("invalid read from memfile")
+	;;
+
+	match bio.read(f, buf[:])
+	| `bio.Ok "lo world":
+		/* ok */
+	| _:
+		std.fatal("invalid read from memfile")
+	;;
+
+	match bio.read(f, buf[:])
+	| `bio.Eof:
+		/* ok */
+	| _:
+		std.fatal("expected eof in memfile")
+	;;
+}
+