summaryrefslogtreecommitdiff
path: root/lib/bio
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-09-11 23:50:09 -0700
committerOri Bernstein <ori@eigenstate.org>2016-09-11 23:50:28 -0700
commitce93c2af0b4aeb2c40a05f2b45c1397b7a2ced23 (patch)
treea8c45070d31937310325caf48f913b0fc9202139 /lib/bio
parentb24a5a737f897466dbf6ff9b3684e9e4d657e658 (diff)
downloadmc-ce93c2af0b4aeb2c40a05f2b45c1397b7a2ced23.tar.gz
Enable and update the bio tests.
Diffstat (limited to 'lib/bio')
-rw-r--r--lib/bio/bld.sub4
-rw-r--r--lib/bio/test/bio-delim.myr20
-rw-r--r--lib/bio/test/bio-endianrd.myr20
-rw-r--r--lib/bio/test/bio-endianwr.myr10
-rw-r--r--lib/bio/test/bio-peek.myr14
-rw-r--r--lib/bio/test/bio-read.myr7
-rw-r--r--[-rwxr-xr-x]lib/bio/test/data/bio-endianwr-expected2
7 files changed, 47 insertions, 30 deletions
diff --git a/lib/bio/bld.sub b/lib/bio/bld.sub
index a7467a1..04469c0 100644
--- a/lib/bio/bld.sub
+++ b/lib/bio/bld.sub
@@ -7,3 +7,7 @@ lib bio =
lib ../std:std
lib ../sys:sys
;;
+
+sub =
+ test
+;;
diff --git a/lib/bio/test/bio-delim.myr b/lib/bio/test/bio-delim.myr
index 139b542..354dc50 100644
--- a/lib/bio/test/bio-delim.myr
+++ b/lib/bio/test/bio-delim.myr
@@ -67,16 +67,24 @@ const main = {
const readln = {f
match bio.readln(f)
- | `std.Some d: -> d
- | `std.None: std.put("eof\n")
- -> [][:]
+ | `bio.Ok d: -> d
+ | `bio.Eof:
+ std.put("eof\n")
+ -> [][:]
+ | `bio.Err e:
+ std.put("err\n")
+ -> [][:]
;;
}
const readto = {f, delim
match bio.readto(f, delim)
- | `std.Some d: -> d
- | `std.None: std.put("eof\n")
- -> [][:]
+ | `bio.Ok d: -> d
+ | `bio.Eof:
+ std.put("eof\n")
+ -> [][:]
+ | `bio.Err e:
+ std.put("err\n")
+ -> [][:]
;;
}
diff --git a/lib/bio/test/bio-endianrd.myr b/lib/bio/test/bio-endianrd.myr
index bad5d57..e445459 100644
--- a/lib/bio/test/bio-endianrd.myr
+++ b/lib/bio/test/bio-endianrd.myr
@@ -1,12 +1,13 @@
use std
use bio
-generic try = {opt : std.option(@a::(integral,numeric))-> @a::(integral,numeric)
+generic try = {opt : bio.status(@a::(integral,numeric))-> @a::(integral,numeric)
match opt
- | `std.Some val: -> val
- | `std.None: std.fatal("read failed")
+ | `bio.Ok val: -> val
+ | _: std.fatal("read failed")
;;
}
+
const main = {
var b : byte
var w : uint16
@@ -21,13 +22,10 @@ const main = {
;;
/* byte */
- /*
- /* FIXME: compiler bug. multiplication on byte
- values is currently broken. */
b = 0xaa
- std.assert(try(bio.getle8(f)) == b, "le byte broken\n")
+ var r = try(bio.getle8(f))
+ std.assert(r == b, "le byte broken: {x}\n", r)
std.assert(try(bio.getbe8(f)) == b, "be byte broken\n")
- */
/* word */
w = 0xaabb
@@ -46,8 +44,10 @@ const main = {
/* end of file */
match bio.getle64(f)
- | `std.None:
- | `std.Some v:
+ | `bio.Eof:
+ | `bio.Err _:
+ std.die("error on reading file\n")
+ | `bio.Ok v:
std.die("read past end of file\n")
v = q /* shut up type inference */
;;
diff --git a/lib/bio/test/bio-endianwr.myr b/lib/bio/test/bio-endianwr.myr
index c4391f3..6a418ac 100644
--- a/lib/bio/test/bio-endianwr.myr
+++ b/lib/bio/test/bio-endianwr.myr
@@ -8,19 +8,15 @@ const main = {
var q : uint64
var f
- match bio.create("tmpout/test-endianwr", bio.Wr, 0o644)
+ match bio.create("data/out-endianwr", bio.Wr, 0o644)
| `std.Ok bio: f = bio
| `std.Err m: std.fatal("Unable to open data file: {}\n", m)
;;
/* byte */
- /*
- /* FIXME: compiler bug. multiplication on byte
- values is currently broken. */
b = 0xaa
- bio.putle(f, b)
- bio.putbe(f, b)
- */
+ bio.putle8(f, b)
+ bio.putbe8(f, b)
/* word */
w = 0xaabb
diff --git a/lib/bio/test/bio-peek.myr b/lib/bio/test/bio-peek.myr
index 062464c..c6528cb 100644
--- a/lib/bio/test/bio-peek.myr
+++ b/lib/bio/test/bio-peek.myr
@@ -28,18 +28,24 @@ const main = {
const peekc = {f
match bio.peekc(f)
- | `std.Some c: -> c
- | `std.None:
+ | `bio.Ok c: -> c
+ | `bio.Eof:
std.put("eof")
-> -1
+ | `bio.Err e:
+ std.fatal("error reading\n")
+ -> -1
;;
}
const peekb = {f
match bio.peekb(f)
- | `std.Some b: -> b
- | `std.None:
+ | `bio.Ok b: -> b
+ | `bio.Eof:
std.put("eof")
-> -1
+ | `bio.Err e:
+ std.fatal("error reading\n")
+ -> -1
;;
}
diff --git a/lib/bio/test/bio-read.myr b/lib/bio/test/bio-read.myr
index 5db9274..c4491b9 100644
--- a/lib/bio/test/bio-read.myr
+++ b/lib/bio/test/bio-read.myr
@@ -40,10 +40,13 @@ const main = {
const r = {f, buf
match bio.read(f, buf)
- | `std.Some b:
+ | `bio.Ok b:
-> b
- | `std.None:
+ | `bio.Eof:
std.put("eof\n")
-> ""
+ | `bio.Err e:
+ std.put("err\n")
+ -> ""
;;
}
diff --git a/lib/bio/test/data/bio-endianwr-expected b/lib/bio/test/data/bio-endianwr-expected
index 8baa404..5e69b1b 100755..100644
--- a/lib/bio/test/data/bio-endianwr-expected
+++ b/lib/bio/test/data/bio-endianwr-expected
@@ -1 +1 @@
-华萏华梯萏华D3""3D梯 \ No newline at end of file
+华萏华梯萏华D3""3D梯 \ No newline at end of file