summaryrefslogtreecommitdiff
path: root/test/junit
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2015-02-03 15:40:30 +0100
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2015-02-03 15:40:30 +0100
commit745ed5c8f6431400cb432cfec751351b3bbd88f0 (patch)
tree17b40dce0d6959c0f46ceea03083cf27a6bcd4e0 /test/junit
parentfc5442780d74bce507146289f6013ef4056e1ec5 (diff)
parent7dc25f9c9f9b2cb73a39e9dc30d01336a1e36da1 (diff)
downloadscala-745ed5c8f6431400cb432cfec751351b3bbd88f0.tar.gz
scala-745ed5c8f6431400cb432cfec751351b3bbd88f0.tar.bz2
scala-745ed5c8f6431400cb432cfec751351b3bbd88f0.zip
Merge pull request #4204 from mpociecha/correct-decimal-marks-in-tests
Fix problems with a locale-dependent decimal mark in StringContextTest
Diffstat (limited to 'test/junit')
-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)
}