summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormpociecha <michal.pociecha@gmail.com>2014-12-14 20:14:29 +0100
committermpociecha <michal.pociecha@gmail.com>2014-12-14 20:45:40 +0100
commit7dc25f9c9f9b2cb73a39e9dc30d01336a1e36da1 (patch)
tree1f0cf1bb9588cca9b8505ccf4b323505ffe149aa /test
parentd9f623db0ff1d20040939fbb9e15d4d4e5887c75 (diff)
downloadscala-7dc25f9c9f9b2cb73a39e9dc30d01336a1e36da1.tar.gz
scala-7dc25f9c9f9b2cb73a39e9dc30d01336a1e36da1.tar.bz2
scala-7dc25f9c9f9b2cb73a39e9dc30d01336a1e36da1.zip
Fix problems with a locale-dependent decimal mark in StringContextTest
This commit corrects three tests which were failing for certain locale due to the different decimal marks in the expected value and the result (e.g. 2.50 and 2,50). From now also the expected value is formatted in accordance with the current locale.
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/StringContextTest.scala15
1 files changed, 12 insertions, 3 deletions
diff --git a/test/junit/scala/StringContextTest.scala b/test/junit/scala/StringContextTest.scala
index 608b82bd96..7e9e775d58 100644
--- a/test/junit/scala/StringContextTest.scala
+++ b/test/junit/scala/StringContextTest.scala
@@ -65,14 +65,23 @@ class StringContextTest {
@Test def fIf() = {
val res = f"${if (true) 2.5 else 2.5}%.2f"
- assertEquals("2.50", res)
+ val expected = formatUsingCurrentLocale(2.50)
+ assertEquals(expected, res)
}
+
@Test def fIfNot() = {
val res = f"${if (false) 2.5 else 3.5}%.2f"
- assertEquals("3.50", res)
+ val expected = formatUsingCurrentLocale(3.50)
+ assertEquals(expected, res)
}
+
@Test def fHeteroArgs() = {
val res = f"${3.14}%.2f rounds to ${3}%d"
- assertEquals("3.14 rounds to 3", res)
+ val expected = formatUsingCurrentLocale(3.14) + " rounds to 3"
+ assertEquals(expected, res)
}
+
+ // 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)
}