Permalink
Browse files

a testsuite to measure format behavior changes and the effectiveness …

…of legacy mode

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14819 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent e69ee15 commit 3ab9516300554c4875be95a397bbb1759fefae56 @gasche gasche committed May 12, 2014
@@ -0,0 +1,3 @@
+BASEDIR=../..
+include $(BASEDIR)/makefiles/Makefile.toplevel
+include $(BASEDIR)/makefiles/Makefile.common
@@ -0,0 +1,22 @@
+(* %n, %l, %N and %L have a scanf-specific semantics, but are supposed
+ to be interpreted by Printf and Format as %u, despite this
+ interpretation being mildly deprecated *)
+
+let test format = (Printf.sprintf format (-3) : string)
+;;
+
+let () = Printf.printf "%%n: %B\n"
+ (test "%n" = test "%u")
+;;
+
+let () = Printf.printf "%%l: %B\n"
+ (test "%l" = test "%u")
+;;
+
+let () = Printf.printf "%%N: %B\n"
+ (test "%N" = test "%u")
+;;
+
+let () = Printf.printf "%%L: %B\n"
+ (test "%L" = test "%u")
+;;
@@ -0,0 +1,7 @@
+
+# * * val test : (int -> string, unit, string) format -> string = <fun>
+# %n: true
+# %l: true
+# %N: true
+# %L: true
+#
@@ -0,0 +1,20 @@
+(* the legacy parser ignores flags on formatters on which they make no
+ sense *)
+
+let () = Printf.printf "%+s\n" "toto"
+;;
+let () = Printf.printf "%#s\n" "toto"
+;;
+let () = Printf.printf "% s\n" "toto"
+;;
+let () = Printf.printf "%03s\n" "toto"
+;;
+let () = Printf.printf "%03S\n" "toto"
+;;
+let () = Printf.printf "%.3s\n" "toto"
+;;
+
+(* it still fails on flags used with ignored formats (%_d, etc.),
+ but it's unclear how to test that in a backward-compatible way,
+ if we accept that the error message may have changed
+*)
@@ -0,0 +1,18 @@
+(* test whether padding modifiers are accepted without any padding
+ size
+
+ the precision modifier is accepted without precision setting, but it
+ defaults to 0, which is not the same thing as not having precision:
+ %.0f 3.5 => 3
+ %.f 3.5 => 3
+ %f 3.5 => 3.5
+*)
+
+let () = Printf.printf "%0d\n" 3
+;;
+let () = Printf.printf "%-d\n" 3
+;;
+let () = Printf.printf "%.d\n" 3
+;;
+let () = Printf.printf "%.f\n" 3.
+;;
@@ -0,0 +1,6 @@
+
+# * * * * * * * * 3
+# 3
+# 3
+# 3
+#

0 comments on commit 3ab9516

Please sign in to comment.