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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/* __ *\
** ________ ___ / / ___ __ ____ Scala.js Test Suite **
** / __/ __// _ | / / / _ | __ / // __/ (c) 2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ http://scala-js.org/ **
** /____/\___/_/ |_/____/_/ | |__/ /____/ **
** |/____/ **
\* */
package scala.scalajs.testsuite.javalib
import java.lang.{Byte => JByte}
import org.scalajs.jasminetest.JasmineTest
/**
* tests the implementation of the java standard library Byte
*/
object ByteTest extends JasmineTest {
describe("java.lang.Byte") {
it("should provide `compareTo`") {
def compare(x: Byte, y: Byte): Int =
new JByte(x).compareTo(new JByte(y))
expect(compare(0.toByte, 5.toByte)).toBeLessThan(0)
expect(compare(10.toByte, 9.toByte)).toBeGreaterThan(0)
expect(compare(-2.toByte, -1.toByte)).toBeLessThan(0)
expect(compare(3.toByte, 3.toByte)).toEqual(0)
}
it("should be a Comparable") {
def compare(x: Any, y: Any): Int =
x.asInstanceOf[Comparable[Any]].compareTo(y)
expect(compare(0.toByte, 5.toByte)).toBeLessThan(0)
expect(compare(10.toByte, 9.toByte)).toBeGreaterThan(0)
expect(compare(-2.toByte, -1.toByte)).toBeLessThan(0)
expect(compare(3.toByte, 3.toByte)).toEqual(0)
}
it("should parse strings") {
def test(s: String, v: Byte): Unit = {
expect(JByte.parseByte(s)).toEqual(v)
expect(JByte.valueOf(s).byteValue()).toEqual(v)
expect(new JByte(s).byteValue()).toEqual(v)
}
test("0", 0)
test("5", 5)
test("127", 127)
test("-100", -100)
}
it("should reject invalid strings when parsing") {
def test(s: String): Unit =
expect(() => JByte.parseByte(s)).toThrow
test("abc")
test("")
test("200") // out of range
}
}
}
|