summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2015-10-24 23:53:59 -0700
committerSom Snytt <som.snytt@gmail.com>2015-10-25 15:00:20 -0700
commitb9ed2bc892bd71a48f110e2f78f2d8192644291c (patch)
tree86cdb75062ad2f0ed24a11b834a29423e1566e4d
parent462dc9af886391c9c31cb6949b15e69b0cab55ef (diff)
downloadscala-b9ed2bc892bd71a48f110e2f78f2d8192644291c.tar.gz
scala-b9ed2bc892bd71a48f110e2f78f2d8192644291c.tar.bz2
scala-b9ed2bc892bd71a48f110e2f78f2d8192644291c.zip
f interp test is junit
Moves test/files/run/stringinterpolation_macro-run.scala to the junit test class test/junit/scala/StringContextTest.scala. Adds a couple of assertions to the test.
-rw-r--r--test/files/run/stringinterpolation_macro-run.check71
-rw-r--r--test/files/run/stringinterpolation_macro-run.scala122
-rw-r--r--test/junit/scala/StringContextTest.scala160
3 files changed, 160 insertions, 193 deletions
diff --git a/test/files/run/stringinterpolation_macro-run.check b/test/files/run/stringinterpolation_macro-run.check
deleted file mode 100644
index c7f46bac87..0000000000
--- a/test/files/run/stringinterpolation_macro-run.check
+++ /dev/null
@@ -1,71 +0,0 @@
-false
-false
-true
-false
-true
-FALSE
-FALSE
-TRUE
-FALSE
-TRUE
-true
-false
-null
-0
-80000000
-4c01926
-NULL
-4C01926
-null
-NULL
-Scala
-SCALA
-5
-x
-x
-x
-x
-x
-x
-x
-x
-x
-x
-x
-x
-S
-120
-120
-120
-120
-120
-120
-120
-120
-120
-120
-120
-120
- 0X4
-She is 4 feet tall.
-120
-42
-3.400000e+00
-3.400000e+00
-3.400000e+00
-3.400000e+00
-3.400000e+00
-3.400000e+00
-3.000000e+00
-3.000000e+00
-05/26/12
-05/26/12
-05/26/12
-05/26/12
-%
- mind
-------
-matter
-
-7 7 9
-7 9 9
diff --git a/test/files/run/stringinterpolation_macro-run.scala b/test/files/run/stringinterpolation_macro-run.scala
deleted file mode 100644
index ae7c0e5d7a..0000000000
--- a/test/files/run/stringinterpolation_macro-run.scala
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * filter: inliner warnings; re-run with
- */
-object Test extends App {
-
-// 'b' / 'B' (category: general)
-// -----------------------------
-println(f"${null}%b")
-println(f"${false}%b")
-println(f"${true}%b")
-println(f"${new java.lang.Boolean(false)}%b")
-println(f"${new java.lang.Boolean(true)}%b")
-
-println(f"${null}%B")
-println(f"${false}%B")
-println(f"${true}%B")
-println(f"${new java.lang.Boolean(false)}%B")
-println(f"${new java.lang.Boolean(true)}%B")
-
-implicit val stringToBoolean = java.lang.Boolean.parseBoolean(_: String)
-println(f"${"true"}%b")
-println(f"${"false"}%b")
-
-// 'h' | 'H' (category: general)
-// -----------------------------
-println(f"${null}%h")
-println(f"${0.0}%h")
-println(f"${-0.0}%h")
-println(f"${"Scala"}%h")
-
-println(f"${null}%H")
-println(f"${"Scala"}%H")
-
-// 's' | 'S' (category: general)
-// -----------------------------
-println(f"${null}%s")
-println(f"${null}%S")
-println(f"${"Scala"}%s")
-println(f"${"Scala"}%S")
-println(f"${5}")
-
-// 'c' | 'C' (category: character)
-// -------------------------------
-println(f"${120:Char}%c")
-println(f"${120:Byte}%c")
-println(f"${120:Short}%c")
-println(f"${120:Int}%c")
-println(f"${new java.lang.Character('x')}%c")
-println(f"${new java.lang.Byte(120:Byte)}%c")
-println(f"${new java.lang.Short(120:Short)}%c")
-println(f"${new java.lang.Integer(120)}%c")
-
-println(f"${'x' : java.lang.Character}%c")
-println(f"${(120:Byte) : java.lang.Byte}%c")
-println(f"${(120:Short) : java.lang.Short}%c")
-println(f"${120 : java.lang.Integer}%c")
-
-implicit val stringToChar = (x: String) => x(0)
-println(f"${"Scala"}%c")
-
-// 'd' | 'o' | 'x' | 'X' (category: integral)
-// ------------------------------------------
-println(f"${120:Byte}%d")
-println(f"${120:Short}%d")
-println(f"${120:Int}%d")
-println(f"${120:Long}%d")
-println(f"${new java.lang.Byte(120:Byte)}%d")
-println(f"${new java.lang.Short(120:Short)}%d")
-println(f"${new java.lang.Integer(120)}%d")
-println(f"${new java.lang.Long(120)}%d")
-println(f"${120 : java.lang.Integer}%d")
-println(f"${120 : java.lang.Long}%d")
-println(f"${BigInt(120)}%d")
-println(f"${new java.math.BigInteger("120")}%d")
-println(f"${4}%#10X")
-
-locally {
- val fff = new java.util.Formattable {
- def formatTo(f: java.util.Formatter, g: Int, w: Int, p: Int) = f.format("4")
- }
- println(f"She is ${fff}%#s feet tall.")
-}
-
-{
- implicit val strToShort = (s: String) => java.lang.Short.parseShort(s)
- println(f"${"120"}%d")
- implicit val strToInt = (s: String) => 42
- println(f"${"120"}%d")
-}
-
-// 'e' | 'E' | 'g' | 'G' | 'f' | 'a' | 'A' (category: floating point)
-// ------------------------------------------------------------------
-println(f"${3.4f}%e")
-println(f"${3.4}%e")
-println(f"${3.4f : java.lang.Float}%e")
-println(f"${3.4 : java.lang.Double}%e")
-println(f"${BigDecimal(3.4)}%e")
-println(f"${new java.math.BigDecimal(3.4)}%e")
-println(f"${3}%e")
-println(f"${3L}%e")
-
-// 't' | 'T' (category: date/time)
-// -------------------------------
-import java.util.Calendar
-import java.util.Locale
-val c = Calendar.getInstance(Locale.US)
-c.set(2012, Calendar.MAY, 26)
-println(f"${c}%TD")
-println(f"${c.getTime}%TD")
-println(f"${c.getTime.getTime}%TD")
-
-implicit val strToDate = (x: String) => c
-println(f"""${"1234"}%TD""")
-
-
-// literals and arg indexes
-println(f"%%")
-println(f" mind%n------%nmatter%n")
-println(f"${7}%d %<d ${9}%d")
-println(f"${7}%d %2$$d ${9}%d")
-
-}
diff --git a/test/junit/scala/StringContextTest.scala b/test/junit/scala/StringContextTest.scala
index 7e9e775d58..900852fcc6 100644
--- a/test/junit/scala/StringContextTest.scala
+++ b/test/junit/scala/StringContextTest.scala
@@ -1,6 +1,8 @@
package scala
+import language.implicitConversions
+
import org.junit.Test
import org.junit.Assert._
import org.junit.runner.RunWith
@@ -84,4 +86,162 @@ class StringContextTest {
// Use this method to avoid problems with a locale-dependent decimal mark.
// The string interpolation is not used here intentionally as this method is used to test string interpolation.
private def formatUsingCurrentLocale(number: Double, decimalPlaces: Int = 2) = ("%." + decimalPlaces + "f").format(number)
+
+ @Test def `f interpolator baseline`(): Unit = {
+
+ implicit def stringToBoolean(s: String): Boolean = java.lang.Boolean.parseBoolean(s)
+ implicit def stringToChar(s: String): Char = s(0)
+ implicit def str2fmt(s: String): java.util.Formattable = new java.util.Formattable {
+ def formatTo(f: java.util.Formatter, g: Int, w: Int, p: Int) = f.format("%s", s)
+ }
+
+ val b_true = true
+ val b_false = false
+
+ val i = 42
+
+ val f_zero = 0.0
+ val f_zero_- = -0.0
+
+ val s = "Scala"
+
+ val fff = new java.util.Formattable {
+ def formatTo(f: java.util.Formatter, g: Int, w: Int, p: Int) = f.format("4")
+ }
+ import java.util.{ Calendar, Locale }
+ val c = Calendar.getInstance(Locale.US)
+ c.set(2012, Calendar.MAY, 26)
+ implicit def strToDate(x: String): Calendar = c
+
+ val ss = List[(String, String)] (
+ // 'b' / 'B' (category: general)
+ // -----------------------------
+ f"${b_false}%b" -> "false",
+ f"${b_true}%b" -> "true",
+
+ f"${null}%b" -> "false",
+ f"${false}%b" -> "false",
+ f"${true}%b" -> "true",
+ f"${true && false}%b" -> "false",
+ f"${new java.lang.Boolean(false)}%b" -> "false",
+ f"${new java.lang.Boolean(true)}%b" -> "true",
+
+ f"${null}%B" -> "FALSE",
+ f"${false}%B" -> "FALSE",
+ f"${true}%B" -> "TRUE",
+ f"${new java.lang.Boolean(false)}%B" -> "FALSE",
+ f"${new java.lang.Boolean(true)}%B" -> "TRUE",
+
+ f"${"true"}%b" -> "true",
+ f"${"false"}%b"-> "false",
+
+ // 'h' | 'H' (category: general)
+ // -----------------------------
+ f"${null}%h" -> "null",
+ f"${f_zero}%h" -> "0",
+ f"${f_zero_-}%h" -> "80000000",
+ f"${s}%h" -> "4c01926",
+
+ f"${null}%H" -> "NULL",
+ f"${s}%H" -> "4C01926",
+
+ // 's' | 'S' (category: general)
+ // -----------------------------
+ f"${null}%s" -> "null",
+ f"${null}%S" -> "NULL",
+ f"${s}%s" -> "Scala",
+ f"${s}%S" -> "SCALA",
+ f"${5}" -> "5",
+ f"${i}" -> "42",
+ f"${'foo}" -> "'foo",
+
+ f"${Thread.State.NEW}" -> "NEW",
+
+ // 'c' | 'C' (category: character)
+ // -------------------------------
+ f"${120:Char}%c" -> "x",
+ f"${120:Byte}%c" -> "x",
+ f"${120:Short}%c" -> "x",
+ f"${120:Int}%c" -> "x",
+ f"${new java.lang.Character('x')}%c" -> "x",
+ f"${new java.lang.Byte(120:Byte)}%c" -> "x",
+ f"${new java.lang.Short(120:Short)}%c" -> "x",
+ f"${new java.lang.Integer(120)}%c" -> "x",
+
+ f"${'x' : java.lang.Character}%c" -> "x",
+ f"${(120:Byte) : java.lang.Byte}%c" -> "x",
+ f"${(120:Short) : java.lang.Short}%c" -> "x",
+ f"${120 : java.lang.Integer}%c" -> "x",
+
+ f"${"Scala"}%c" -> "S",
+
+ // 'd' | 'o' | 'x' | 'X' (category: integral)
+ // ------------------------------------------
+ f"${120:Byte}%d" -> "120",
+ f"${120:Short}%d" -> "120",
+ f"${120:Int}%d" -> "120",
+ f"${120:Long}%d" -> "120",
+ f"${60 * 2}%d" -> "120",
+ f"${new java.lang.Byte(120:Byte)}%d" -> "120",
+ f"${new java.lang.Short(120:Short)}%d" -> "120",
+ f"${new java.lang.Integer(120)}%d" -> "120",
+ f"${new java.lang.Long(120)}%d" -> "120",
+ f"${120 : java.lang.Integer}%d" -> "120",
+ f"${120 : java.lang.Long}%d" -> "120",
+ f"${BigInt(120)}%d" -> "120",
+
+ f"${new java.math.BigInteger("120")}%d" -> "120",
+
+ f"${4}%#10X" -> " 0X4",
+
+ f"She is ${fff}%#s feet tall." -> "She is 4 feet tall.",
+
+ f"Just want to say ${"hello, world"}%#s..." -> "Just want to say hello, world...",
+
+ { implicit val strToShort = (s: String) => java.lang.Short.parseShort(s) ; f"${"120"}%d" } -> "120",
+ { implicit val strToInt = (s: String) => 42 ; f"${"120"}%d" } -> "42",
+
+ // 'e' | 'E' | 'g' | 'G' | 'f' | 'a' | 'A' (category: floating point)
+ // ------------------------------------------------------------------
+ f"${3.4f}%e" -> "3.400000e+00",
+ f"${3.4}%e" -> "3.400000e+00",
+ f"${3.4f : java.lang.Float}%e" -> "3.400000e+00",
+ f"${3.4 : java.lang.Double}%e" -> "3.400000e+00",
+
+ f"${BigDecimal(3.4)}%e" -> "3.400000e+00",
+
+ f"${new java.math.BigDecimal(3.4)}%e" -> "3.400000e+00",
+
+ f"${3}%e" -> "3.000000e+00",
+ f"${3L}%e" -> "3.000000e+00",
+
+ // 't' | 'T' (category: date/time)
+ // -------------------------------
+ f"${c}%TD" -> "05/26/12",
+ f"${c.getTime}%TD" -> "05/26/12",
+ f"${c.getTime.getTime}%TD" -> "05/26/12",
+ f"""${"1234"}%TD""" -> "05/26/12",
+
+ // literals and arg indexes
+ f"%%" -> "%",
+ f" mind%n------%nmatter%n" ->
+ """| mind
+ |------
+ |matter
+ |""".stripMargin,
+ f"${i}%d %<d ${9}%d" -> "42 42 9",
+ f"${7}%d %<d ${9}%d" -> "7 7 9",
+ f"${7}%d %2$$d ${9}%d" -> "7 9 9",
+
+ f"${null}%d %<B" -> "null FALSE",
+
+ f"${5: Any}" -> "5",
+ f"${5}%s%<d" -> "55",
+ f"${3.14}%s,%<f" -> "3.14,3.140000",
+
+ f"z" -> "z"
+ )
+
+ for ((f, s) <- ss) assertEquals(s, f)
+ }
}