diff options
author | Martin Odersky <odersky@gmail.com> | 2012-01-16 17:49:12 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2012-01-16 17:49:37 +0100 |
commit | 6ea9f72ffd0e1b606cb5ad4670b4db8330fa29b9 (patch) | |
tree | f0e187995ccd498928e521be7653a7eb86f85ea2 /test/files/run/interpolation.scala | |
parent | b0de5f13329aa24752fae079c50cc0584471379e (diff) | |
download | scala-6ea9f72ffd0e1b606cb5ad4670b4db8330fa29b9.tar.gz scala-6ea9f72ffd0e1b606cb5ad4670b4db8330fa29b9.tar.bz2 scala-6ea9f72ffd0e1b606cb5ad4670b4db8330fa29b9.zip |
A string interpolation implementation of SIP-11.
This is the complete implementation of SIP-11, in its version of 15-Jan-2012. For now, the interpolations are enabled only under the -Xexperimental flag.
Diffstat (limited to 'test/files/run/interpolation.scala')
-rw-r--r-- | test/files/run/interpolation.scala | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/files/run/interpolation.scala b/test/files/run/interpolation.scala new file mode 100644 index 0000000000..232a180bcd --- /dev/null +++ b/test/files/run/interpolation.scala @@ -0,0 +1,24 @@ +object Test extends App { + + def test1(n: Int) = { + println(s"Bob is $n years old") + println(f"Bob is $n%2d years old") + println(s"Bob will be ${n+1} years old") + println(f"Bob will be ${n+1}%2d years old") + } + + def test2(f: Float) = { + println(s"Best price: $f") + println(f"Best price: $f%.2f") + println(s"$f% discount included") + println(f"$f%3.2f% discount included") + } + + test1(1) + test1(12) + test1(123) + + test2(10.0f) + test2(13.345f) + +} |