diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2015-02-03 15:40:30 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2015-02-03 15:40:30 +0100 |
commit | 745ed5c8f6431400cb432cfec751351b3bbd88f0 (patch) | |
tree | 17b40dce0d6959c0f46ceea03083cf27a6bcd4e0 /test | |
parent | fc5442780d74bce507146289f6013ef4056e1ec5 (diff) | |
parent | 7dc25f9c9f9b2cb73a39e9dc30d01336a1e36da1 (diff) | |
download | scala-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')
-rw-r--r-- | test/junit/scala/StringContextTest.scala | 15 |
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) } |