ref: 6ac770d6a6001de52e4b099998865ac956a7de5c
parent: f1558a33e06a7b344cac9a351f2879c2f881b28e
author: Ori Bernstein <[email protected]>
date: Wed Dec 18 13:15:24 EST 2013
Add test for peeking.
--- /dev/null
+++ b/test/bio-peek.myr
@@ -1,0 +1,27 @@
+use std
+use bio
+
+const main = {
+ var f
+ /* Must be bigger than a bio buffer (ie, > 64k) */
+ var buf : byte[64*1024]
+
+ match bio.open("data/datafile", bio.Rd)
+ | `std.Some bio: f = bio
+ | `std.None: std.fatal(1, "Unable to open data file")
+ ;;
+
+ std.assert(bio.peekb(f) == 0x30, "wrong byte value read from datafile")
+ std.assert(bio.peekc(f) == '0', "wrong char value read from datafile")
+
+ bio.read(f, buf[:4]) /* skip ahead 4 bytes */
+ std.assert(bio.peekb(f) == 0x34, "wrong byte value read from datafile")
+ std.assert(bio.peekc(f) == '4', "wrong char value read from datafile")
+
+ bio.read(f, buf[:]) /* skip ahead 64k */
+ std.assert(bio.peekb(f) == 0x30, "wrong byte value read from datafile")
+ std.assert(bio.peekc(f) == '0', "wrong char value read from datafile")
+
+ bio.close(f);
+ std.put("Succeded peeeking values\n")
+}
--- a/test/tests
+++ b/test/tests
@@ -27,5 +27,5 @@
B bio-endianwr F tmpout/test-endianwr
B bio-endianrd C
B bio-unitwr F tmpout/test-unitwr
-#B bio-peek C
+B bio-peek C
#B bio-fmt C