]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | /* jshint -W100 */ | |
20 | ||
21 | // Work around for old API used by QUnitAdapter of jsTestDriver | |
22 | if (typeof QUnit.log == 'function') { | |
23 | // When using real QUnit (fron PhantomJS) log failures to console | |
24 | QUnit.log(function(details) { | |
25 | if (!details.result) { | |
26 | console.log('======== FAIL ========'); | |
27 | console.log('TestName: ' + details.name); | |
28 | if (details.message) console.log(details.message); | |
29 | console.log('Expected: ' + details.expected); | |
30 | console.log('Actual : ' + details.actual); | |
31 | console.log('======================'); | |
32 | } | |
33 | }); | |
34 | } | |
35 | ||
36 | QUnit.module('Int64'); | |
37 | ||
38 | QUnit.test('Int64', function(assert) { | |
39 | console.log('Int64 test -- starts'); | |
40 | const EXPECTED_SMALL_INT64_AS_NUMBER = 42; | |
41 | const EXPECTED_SMALL_INT64 = new Int64(42); | |
42 | const EXPECTED_MAX_JS_SAFE_INT64 = new Int64(Number.MAX_SAFE_INTEGER); | |
43 | const EXPECTED_MIN_JS_SAFE_INT64 = new Int64(Number.MIN_SAFE_INTEGER); | |
44 | const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64 = new Int64("0020000000000000"); // hex-encoded | |
45 | const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64 = new Int64("ffe0000000000000"); // hex-encoded 2's complement | |
46 | const EXPECTED_MAX_SIGNED_INT64 = new Int64("7fffffffffffffff"); // hex-encoded | |
47 | const EXPECTED_MIN_SIGNED_INT64 = new Int64("8000000000000000"); // hex-encoded 2's complement | |
48 | const EXPECTED_INT64_LIST = [ | |
49 | EXPECTED_SMALL_INT64, | |
50 | EXPECTED_MAX_JS_SAFE_INT64, | |
51 | EXPECTED_MIN_JS_SAFE_INT64, | |
52 | EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64, | |
53 | EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64, | |
54 | EXPECTED_MAX_SIGNED_INT64, | |
55 | EXPECTED_MIN_SIGNED_INT64 | |
56 | ]; | |
57 | ||
58 | assert.ok(EXPECTED_SMALL_INT64.equals(Int64Test.SMALL_INT64)); | |
59 | assert.ok(EXPECTED_MAX_JS_SAFE_INT64.equals(Int64Test.MAX_JS_SAFE_INT64)); | |
60 | assert.ok(EXPECTED_MIN_JS_SAFE_INT64.equals(Int64Test.MIN_JS_SAFE_INT64)); | |
61 | assert.ok( | |
62 | EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64.equals( | |
63 | Int64Test.MAX_JS_SAFE_PLUS_ONE_INT64 | |
64 | ) | |
65 | ); | |
66 | assert.ok( | |
67 | EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64.equals( | |
68 | Int64Test.MIN_JS_SAFE_MINUS_ONE_INT64 | |
69 | ) | |
70 | ); | |
71 | assert.ok(EXPECTED_MAX_SIGNED_INT64.equals(Int64Test.MAX_SIGNED_INT64)); | |
72 | assert.ok(EXPECTED_MIN_SIGNED_INT64.equals(Int64Test.MIN_SIGNED_INT64)); | |
73 | assert.equal( | |
74 | EXPECTED_SMALL_INT64_AS_NUMBER, | |
75 | Int64Test.SMALL_INT64.toNumber() | |
76 | ); | |
77 | assert.equal( | |
78 | Number.MAX_SAFE_INTEGER, | |
79 | Int64Test.MAX_JS_SAFE_INT64.toNumber() | |
80 | ); | |
81 | assert.equal( | |
82 | Number.MIN_SAFE_INTEGER, | |
83 | Int64Test.MIN_JS_SAFE_INT64.toNumber() | |
84 | ); | |
85 | ||
86 | for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { | |
87 | assert.ok(EXPECTED_INT64_LIST[i].equals(Int64Test.INT64_LIST[i])); | |
88 | } | |
89 | ||
90 | for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i){ | |
91 | let int64Object = EXPECTED_INT64_LIST[i]; | |
92 | assert.ok(Int64Test.INT64_2_INT64_MAP[JSONInt64.toDecimalString(int64Object)].equals(int64Object)); | |
93 | } | |
94 | ||
95 | console.log('Int64 test -- ends'); | |
96 | }); | |
97 |