Adding tests for conversion format %n.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5317 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Pierre Weis 2002-12-08 16:05:32 +00:00
parent 6cdad3430c
commit d86fe5a9ed
2 changed files with 26 additions and 11 deletions

View File

@ -117,6 +117,10 @@ tscanf.byt: tscanf.cmo
tscanf.out: tscanf.cmx tscanf.out: tscanf.cmx
${CAMLOPT} -o tscanf.out tscanf.cmx ${CAMLOPT} -o tscanf.out tscanf.cmx
scanf: tscanf.byt tscanf.out
./tscanf.byt
./tscanf.out
# Common rules # Common rules
.SUFFIXES: .SUFFIXES:

View File

@ -257,9 +257,9 @@ let test11 () =
;; ;;
let test110 () = let test110 () =
sscanf "" "\n" (fun x -> x) "" = "" && sscanf "" " " (fun x -> x) "" = "" &&
sscanf "" "%[^\n]" (fun x -> x) = "" && sscanf "" "%[^\n]" (fun x -> x) = "" &&
sscanf "" "%[^\n]\n" (fun x -> x) = "";; sscanf "" "%[^\n] " (fun x -> x) = "";;
let test111 () = let test111 () =
test_raises_this_exc End_of_file (sscanf "" "%[^\n]@\n") (fun x -> x);; test_raises_this_exc End_of_file (sscanf "" "%[^\n]@\n") (fun x -> x);;
@ -707,20 +707,31 @@ test (test34 ());;
let test35 () = let test35 () =
sscanf "" "%N" (fun x -> x) = 0 && sscanf "" "%N" (fun x -> x) = 0 &&
sscanf "456" "%N" (fun x -> x) = 0 && sscanf "456" "%N" (fun x -> x) = 0 &&
sscanf "456" "%d%N" (fun x y -> x, y) = (456, 3);; sscanf "456" "%d%N" (fun x y -> x, y) = (456, 1) &&
test (test35 ());;
(* Weird tests to empty strings or formats. *)
let test36 () =
sscanf "" "" true &&
sscanf "" "" (fun x -> x) 1 = 1 &&
sscanf "123" "" (fun x -> x) 1 = 1 &&
sscanf " " "%N%s%N" (fun x s y -> x, s, y) = (0, "", 1) sscanf " " "%N%s%N" (fun x s y -> x, s, y) = (0, "", 1)
;; ;;
test (test35 ());;
(* Testing the %n format. *)
let test36 () =
sscanf "" "%n" (fun x -> x) = 0 &&
sscanf "456" "%n" (fun x -> x) = 0 &&
sscanf "456" "%d%n" (fun x y -> x, y) = (456, 3) &&
sscanf " " "%n%s%n" (fun x s y -> x, s, y) = (0, "", 1)
;;
test (test36 ());; test (test36 ());;
(* Weird tests to empty strings or formats. *)
let test37 () =
sscanf "" "" true &&
sscanf "" "" (fun x -> x) 1 = 1 &&
sscanf "123" "" (fun x -> x) 1 = 1
;;
test (test37 ());;
(******* (*******
print_string "Test number is "; print_string "Test number is ";