Adding tests for positional parameters.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7334 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
dca5609f32
commit
abc46ae8d3
|
@ -2,8 +2,9 @@ open Testing;;
|
|||
|
||||
open Printf;;
|
||||
|
||||
(* Padding floating point numbers.
|
||||
Testing * width specifications. *)
|
||||
let test0 () =
|
||||
sprintf "%d\n" 1 = "1\n" &&
|
||||
sprintf "%.0f" 1.0 = "1" &&
|
||||
sprintf "%.0f." 1.7 = "2." &&
|
||||
sprintf "%.1f." 1.0 = "1.0." &&
|
||||
|
@ -30,8 +31,41 @@ test (test0 ());;
|
|||
(* Padding integers (cf bug 3955).
|
||||
Testing * width specifications. *)
|
||||
let test1 () =
|
||||
sprintf "%05d\n" 1 = "00001" &&
|
||||
sprintf "%*d\n" 5 1 = " 1" &&
|
||||
sprintf "%0*d\n" 5 1 = " 1";;
|
||||
sprintf "%d\n" 1 = "1\n" &&
|
||||
sprintf "%05d\n" 1 = "00001\n" &&
|
||||
sprintf "%*d\n" 5 1 = " 1\n" &&
|
||||
sprintf "%0*d\n" 5 1 = "00001\n";;
|
||||
|
||||
test (test1 ());;
|
||||
|
||||
let test2 () =
|
||||
sprintf "%1$d\n" 5 1 = " 1\n" &&
|
||||
sprintf "%01$d\n" 5 1 = "00001\n";;
|
||||
|
||||
test (test2 ());;
|
||||
|
||||
(* Testing meta format string printing. *)
|
||||
let test3 () =
|
||||
sprintf "%{toto %s titi.\n%}" "Bonjour %s." = "%s" &&
|
||||
sprintf "%{%d%s%}" "kk%dkk%s\n" = "%i%s";;
|
||||
test (test3 ());;
|
||||
|
||||
(* Testing meta format string arguments. *)
|
||||
let test4 () =
|
||||
sprintf "%(%s%)" "Bonjour %s" "toto" = "Bonjour toto" &&
|
||||
sprintf "%(%s%)" "Bonjour %s." "vous" = "Bonjour vous." &&
|
||||
sprintf "%(%s%)" "Hello %s." "you" = "Hello you."
|
||||
;;
|
||||
|
||||
test (test4 ());;
|
||||
|
||||
let test5 () =
|
||||
sprintf "%(toto %s titi.\n%)"
|
||||
"Bonjour %s." "vous" = "Bonjour vous." &&
|
||||
sprintf "%(toto %s titi.\n%).\n"
|
||||
"Bonjour %s" "toto" = "Bonjour toto.\n" &&
|
||||
sprintf "%(toto %s titi.\n%)%s\n"
|
||||
"Bonjour %s." "toto" " Ça va?" = "Bonjour toto. Ça va?\n"
|
||||
;;
|
||||
|
||||
test (test5 ());;
|
||||
|
|
Loading…
Reference in New Issue