summaryrefslogtreecommitdiff
path: root/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/CharTest.scala
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/CharTest.scala')
-rw-r--r--examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/CharTest.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/CharTest.scala b/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/CharTest.scala
new file mode 100644
index 0000000..edc2660
--- /dev/null
+++ b/examples/scala-js/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/CharTest.scala
@@ -0,0 +1,40 @@
+/* __ *\
+** ________ ___ / / ___ __ ____ Scala.js Test Suite **
+** / __/ __// _ | / / / _ | __ / // __/ (c) 2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ http://scala-js.org/ **
+** /____/\___/_/ |_/____/_/ | |__/ /____/ **
+** |/____/ **
+\* */
+package scala.scalajs.testsuite.compiler
+
+import org.scalajs.jasminetest.JasmineTest
+import scala.scalajs.js.Any.fromInt
+
+object CharTest extends JasmineTest {
+
+ describe("Char primitives") {
+
+ it("should always be positive (when coerced)") {
+ expect(-3.toByte.toChar.toInt).toEqual(65533)
+ expect(-100.toShort.toChar.toInt).toEqual(65436)
+ expect(-66000.toChar.toInt).toEqual(65072)
+ expect(-4567L.toChar.toInt).toEqual(60969)
+ expect(-5.3f.toChar.toInt).toEqual(65531)
+ expect(-7.9.toChar.toInt).toEqual(65529)
+ }
+
+ it("should overflow (when coerced)") {
+ expect(347876543.toChar.toInt).toEqual(11455)
+ expect(34234567876543L.toChar.toInt).toEqual(57279)
+ }
+
+ it("should overflow with *") {
+ def test(a: Char, b: Char, expected: Int): Unit =
+ expect(a * b).toEqual(expected)
+
+ // note: expected values are constant-folded by the compiler on the JVM
+ test(Char.MaxValue, Char.MaxValue, Char.MaxValue * Char.MaxValue)
+ }
+
+ }
+}