summaryrefslogtreecommitdiff
path: root/lib/bio
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-06-11 20:48:28 -0700
committerOri Bernstein <ori@eigenstate.org>2017-06-11 20:48:28 -0700
commitc505373d1bbcad1e7861f6db054eddcfd5cac354 (patch)
tree2ffb4ab42a468778e8b6ba73a6a635d44da99a8e /lib/bio
parentb88dc2174f25b7ca08a0a7bc42bf981488de54c9 (diff)
downloadmc-c505373d1bbcad1e7861f6db054eddcfd5cac354.tar.gz
Add memfiles.
Diffstat (limited to 'lib/bio')
-rw-r--r--lib/bio/bld.sub1
-rw-r--r--lib/bio/test/mem.myr30
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/bio/bld.sub b/lib/bio/bld.sub
index 04469c0..95eeca2 100644
--- a/lib/bio/bld.sub
+++ b/lib/bio/bld.sub
@@ -3,6 +3,7 @@ lib bio =
geti.myr
puti.myr
iter.myr
+ mem.myr
lib ../std:std
lib ../sys:sys
diff --git a/lib/bio/test/mem.myr b/lib/bio/test/mem.myr
new file mode 100644
index 0000000..f3135d2
--- /dev/null
+++ b/lib/bio/test/mem.myr
@@ -0,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")
+ ;;
+}
+