blob: edc2660d9434aafa9272da9036d051429829f514 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
}
}
}
|