1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
(* Auxiliary functions for test cases *)
infix 1 seq
fun e1 seq e2 = e2;
fun check b = if b then "OK" else "WRONG";
fun check' f = (if f () then "OK" else "WRONG") handle _ => "EXN";
fun range (from, to) p =
let open Int
in
(from > to) orelse (p from) andalso (range (from+1, to) p)
end;
fun checkrange bounds = check o range bounds;
fun tst0 s s' = print (s ^ " \t" ^ s' ^ "\n");
fun tst s b = tst0 s (check b);
fun tst' s f = tst0 s (check' f);
fun tstrange s bounds = (tst s) o range bounds
(* General -- incomplete 1996-04-19, 1996-09-30, 1997-03-12 *)
val _ = print "\nFile general.sml: Testing structure General...\n"
exception NoExceptionRaised
fun getExn (f : unit -> 'a) =
(f (); NoExceptionRaised) handle e => e
fun prExn(exnStr, exn) =
(print "Should be `"; print exnStr; print "':\n ";
print (exnName exn); print "\n ";
print (exnMessage exn); print "\n");
exception E1;
exception E2 = E1;
val _ = List.map prExn
[("E1 or E2", E2),
("Bind", getExn(fn _ => let val true = false in () end)),
("Match", getExn(fn _ => (fn true => ()) false)),
("Subscript", getExn(fn _ => Vector.sub(vector [], ~1))),
("Overflow", getExn(fn _ => Array.array(Array.maxLen+1, ()))),
(* ("Overflow", getExn(fn _ => Math.exp 1E99)),
("Domain", getExn(fn _ => Math.ln ~1.0)),
*) ("Div", getExn(fn _ => 1 div 0)),
("Chr", getExn(fn _ => Char.chr 9999999)),
("Fail", Fail "demo"),
("Option", getExn(fn _ => valOf NONE)),
("Empty", getExn(fn _ => List.hd []))
(* ("SysErr", getExn (fn _ => FileSys.modTime "exists.not")), *)
(* ("Io", getExn (fn _ => TextIO.openOut "."))*)
];
|