summaryrefslogtreecommitdiff
path: root/test-suite/src/test/scala/scala/scalajs/testsuite/compiler/ByteTest.scala
blob: 9f48993de3457df517b02cbc86359dfef824dc39 (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

object ByteTest extends JasmineTest {

  describe("Byte primitives") {

    it("should always be in their range") {
      def test(x: Int, y: Byte): Unit =
        expect(x.toByte).toEqual(y)

      test(0, 0)
      test(127, 127)
      test(128, -128)
      test(-128, -128)
      test(-500, 12)
      test(-90000, 112)
      test(123456789, 21)
      test(-40000, -64)
      test(65536, 0)
      test(32768, 0)

      def testC(x: Char, y: Byte): Unit =
        expect(x.toByte).toEqual(y)

      testC(-1.toChar, -1)
      testC(200.toChar, -56)
    }

  }
}