summaryrefslogtreecommitdiff
path: root/test/files/neg/stringinterpolation_macro-neg.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-01-28 01:37:11 -0800
committerSom Snytt <som.snytt@gmail.com>2014-01-28 09:42:32 -0800
commit8053682d4ff0dcff3c1846a1bac9c718c92cc704 (patch)
treeafb0b22c79c389997ad37585b2c01603a5f4284b /test/files/neg/stringinterpolation_macro-neg.scala
parentf22ddce265e8622e95f5e9cab4d38168bf2c3bf8 (diff)
downloadscala-8053682d4ff0dcff3c1846a1bac9c718c92cc704.tar.gz
scala-8053682d4ff0dcff3c1846a1bac9c718c92cc704.tar.bz2
scala-8053682d4ff0dcff3c1846a1bac9c718c92cc704.zip
SI-8092 More verify for f-interpolator
Attempt to verify the nooks and crannies of the format string. Allows all syntax in the javadoc, including arg indexes. If the specifier after an arg has an index that doesn't refer to the arg, a warning is issued and the missing `%s` is prepended (just as for a part with a leading `%n`). Other enhancements include detecting that a `Formattable` wasn't supplied to `%#s`. Error messages attempt to be pithy but descriptive.
Diffstat (limited to 'test/files/neg/stringinterpolation_macro-neg.scala')
-rw-r--r--test/files/neg/stringinterpolation_macro-neg.scala42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/files/neg/stringinterpolation_macro-neg.scala b/test/files/neg/stringinterpolation_macro-neg.scala
index ac9d97d678..c5ae708f21 100644
--- a/test/files/neg/stringinterpolation_macro-neg.scala
+++ b/test/files/neg/stringinterpolation_macro-neg.scala
@@ -3,6 +3,11 @@ object Test extends App {
val d = 8
val b = false
val f = 3.14159
+ val c = 'c'
+ val t = new java.util.Date
+ val x = new java.util.Formattable {
+ def formatTo(ff: java.util.Formatter, g: Int, w: Int, p: Int): Unit = ff format "xxx"
+ }
// 1) number of arguments
new StringContext().f()
@@ -28,4 +33,41 @@ object Test extends App {
}
f"$s%i"
+
+ // 3) flag mismatches
+ f"$s%+ 0,(s"
+ f"$c%#+ 0,(c"
+ f"$d%#d"
+ f"$d%,x"
+ f"$d%+ (x"
+ f"$f%,(a"
+ f"$t%#+ 0,(tT"
+
+ // 4) bad precisions
+ f"$c%.2c"
+ f"$d%.2d"
+ f"%.2%"
+ f"%.2n"
+ f"$f%.2a"
+ f"$t%.2tT"
+
+ // 5) bad indexes
+ f"%<s"
+ f"%<c"
+ f"%<tT"
+ f"${8}%d ${9}%d%3$$d"
+ f"${8}%d ${9}%d%0$$d"
+
+ // warnings
+ f"${8}%d ${9}%1$$d"
+ f"$s%s $s%s %1$$<s"
+ f"$s%s $s%1$$s"
+
+ // 6) bad arg types
+ f"$s%#s"
+
+ // 7) misunderstood conversions
+ f"$t%tG"
+ f"$t%t"
+ f"$s%10.5"
}