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
|
/* __ *\
** ________ ___ / / ___ __ ____ Scala.js Test Suite **
** / __/ __// _ | / / / _ | __ / // __/ (c) 2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ http://scala-js.org/ **
** /____/\___/_/ |_/____/_/ | |__/ /____/ **
** |/____/ **
\* */
package scala.scalajs.testsuite.javalib
import java.lang.{Boolean => JBoolean}
import org.scalajs.jasminetest.JasmineTest
/**
* tests the implementation of the java standard library Boolean
*/
object BooleanTest extends JasmineTest {
describe("java.lang.Boolean") {
it("should provide `booleanValue`") {
expect(JBoolean.TRUE.booleanValue()).toBe(true)
expect(JBoolean.FALSE.booleanValue()).toBe(false)
expect(() => (null: JBoolean).booleanValue()).toThrow
}
it("should provide `compareTo`") {
def compare(x: Boolean, y: Boolean): Int =
new JBoolean(x).compareTo(new JBoolean(y))
expect(compare(false, false)).toEqual(0)
expect(compare(false, true)).toBeLessThan(0)
expect(compare(true, false)).toBeGreaterThan(0)
expect(compare(true, true)).toEqual(0)
}
it("should be a Comparable") {
def compare(x: Any, y: Any): Int =
x.asInstanceOf[Comparable[Any]].compareTo(y)
expect(compare(false, false)).toEqual(0)
expect(compare(false, true)).toBeLessThan(0)
expect(compare(true, false)).toBeGreaterThan(0)
expect(compare(true, true)).toEqual(0)
}
it("should parse strings") {
def test(s: String, v: Boolean): Unit = {
expect(JBoolean.parseBoolean(s)).toEqual(v)
expect(JBoolean.valueOf(s).booleanValue()).toEqual(v)
expect(new JBoolean(s).booleanValue()).toEqual(v)
}
test("false", false)
test("true", true)
test("TrUe", true)
test(null, false)
test("truee", false)
}
}
}
|