summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Weis <Pierre.Weis@inria.fr>2006-01-18 17:17:40 +0000
committerPierre Weis <Pierre.Weis@inria.fr>2006-01-18 17:17:40 +0000
commitf5c8363ce1a61f318e18d0d2e81aa09e096d0e5e (patch)
tree4ef6409fdd7bc3a8656faebeb8ebf4f34ffe45a9
parent53d9cb95a9e3251adc2aa2c168971e5a1ce7dfba (diff)
Adding a test for scanning of native, int32 and int64 integers.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7328 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--test/Moretest/tscanf.ml103
1 files changed, 18 insertions, 85 deletions
diff --git a/test/Moretest/tscanf.ml b/test/Moretest/tscanf.ml
index cd66076c0..0ba38f767 100644
--- a/test/Moretest/tscanf.ml
+++ b/test/Moretest/tscanf.ml
@@ -1,83 +1,6 @@
-open Scanf;;
-
-(* Auxilliaries. *)
-let all_tests_ok = ref true;;
-
-let finish () =
- match !all_tests_ok with
- | true ->
- prerr_endline "\nAll tests succeeded."
- | _ ->
- prerr_endline "\n\n********* Test suit failed. ***********\n";;
-
-at_exit finish;;
-
-let test_num = ref (-1);;
-
-let print_test_number () =
- print_int !test_num; print_string " "; flush stdout;;
-
-let next_test () =
- incr test_num;
- print_test_number ();;
-
-let print_test_fail () =
- all_tests_ok := false;
- print_string
- (Printf.sprintf "\n********* Test number %i failed ***********\n"
- !test_num);;
-
-let print_failure_test_fail () =
- all_tests_ok := false;
- print_string
- (Printf.sprintf
- "\n********* Failure Test number %i incorrectly failed ***********\n"
- !test_num);;
-
-let print_failure_test_succeed () =
- all_tests_ok := false;
- print_string
- (Printf.sprintf
- "\n********* Failure Test number %i failed to fail ***********\n"
- !test_num);;
-
-let test b =
- next_test ();
- if not b then print_test_fail ();;
-
-(* Applies f to x and checks that the evaluation indeed
- raises an exception that verifies the predicate [pred]. *)
-let test_raises_exc_p pred f x =
- next_test ();
- try
- ignore (f x);
- print_failure_test_succeed ();
- false
- with
- | x ->
- pred x || (print_failure_test_fail (); false);;
-
-(* Applies f to x and checks that the evaluation indeed
- raises some exception. *)
-let test_raises_some_exc f = test_raises_exc_p (fun _ -> true) f;;
-let test_raises_this_exc exc = test_raises_exc_p (fun x -> x = exc);;
-
-(* Applies f to x and checks that the evaluation indeed
- raises exception Failure s. *)
-
-let test_raises_this_failure s f x =
- test_raises_exc_p (fun x -> x = Failure s) f x;;
+open Testing;;
-(* Applies f to x and checks that the evaluation indeed
- raises the exception Failure. *)
-let test_raises_some_failure f x =
- test_raises_exc_p (function Failure _ -> true | _ -> false) f x;;
-
-let failure_test f x s = test_raises_this_failure s f x;;
-let any_failure_test = test_raises_some_failure;;
-
-let scan_failure_test f x =
- test_raises_exc_p (function Scan_failure _ -> true | _ -> false) f x;;
+open Scanf;;
(* The ``continuation'' that returns the scanned value. *)
let id x = x;;
@@ -870,12 +793,10 @@ test (test45 ());;
let test46, test47 =
(fun () ->
- Printf.sprintf
- (format_of_string "%i %(%s%).")
+ Printf.sprintf "%i %(%s%)."
1 "spells one, %s" "in english"),
(fun () ->
- Printf.sprintf
- (format_of_string "%i ,%{%s%}, %s.")
+ Printf.sprintf "%i ,%{%s%}, %s."
1 "spells one %s" "in english");;
test (test46 () = "1 spells one, in english.");;
@@ -972,7 +893,7 @@ let test51 () =
test (test51 ());;
-(* Tests that indeed %s@c works properly.
+(* Tests that indeed %s@c format works properly.
Also tests the difference between \n and @\n.
In particular, tests that if no c character can be found in the
input, then the token obtained for %s@c spreads to the end of
@@ -993,8 +914,20 @@ let test52 () =
test (test52 ());;
-(*******
+(* Reading native, int32 and int64 numbers. *)
+let test53 () =
+ sscanf "123" "%nd" id = 123n &&
+ sscanf "124" "%nd" (fun i -> Nativeint.pred i = 123n) &&
+ sscanf "123" "%ld" id = 123l &&
+ sscanf "124" "%ld" (fun i -> Int32.succ i = 125l) &&
+
+ sscanf "123" "%Ld" id = 123L &&
+ sscanf "124" "%Ld" (fun i -> Int64.pred i = 123L);;
+
+test (test53 ());;
+
+(*******
To be continued.
let digest () =