blob: 3ea7919e2c8d58c308a88a6b5eaa67b554322e66 [file] [log] [blame]
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +03001/*
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
21var Int64 = require("node-int64");
22import { Int64Test } from "./gen-js/Int64Test_types";
23
24
25// Work around for old API used by QUnitAdapter of jsTestDriver
26if (typeof QUnit.log == 'function') {
27 // When using real QUnit (fron PhantomJS) log failures to console
28 QUnit.log(function(details) {
29 if (!details.result) {
30 console.log('======== FAIL ========');
31 console.log('TestName: ' + details.name);
32 if (details.message) console.log(details.message);
33 console.log('Expected: ' + details.expected);
34 console.log('Actual : ' + details.actual);
35 console.log('======================');
36 }
37 });
38}
39
40QUnit.module('Int64');
41
42 QUnit.test('Int64', function(assert) {
43 console.log('Int64 test -- starts');
44 const EXPECTED_SMALL_INT64_AS_NUMBER: number = 42;
45 const EXPECTED_SMALL_INT64: typeof Int64 = new Int64(42);
46 const EXPECTED_MAX_JS_SAFE_INT64: typeof Int64 = new Int64(Number.MAX_SAFE_INTEGER);
47 const EXPECTED_MIN_JS_SAFE_INT64: typeof Int64 = new Int64(Number.MIN_SAFE_INTEGER);
48 const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64: typeof Int64 = new Int64("0020000000000000"); // hex-encoded
49 const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64: typeof Int64 = new Int64("ffe0000000000000"); // hex-encoded 2's complement
50 const EXPECTED_MAX_SIGNED_INT64: typeof Int64 = new Int64("7fffffffffffffff"); // hex-encoded
51 const EXPECTED_MIN_SIGNED_INT64: typeof Int64 = new Int64("8000000000000000"); // hex-encoded 2's complement
52 const EXPECTED_INT64_LIST = [
53 EXPECTED_SMALL_INT64,
54 EXPECTED_MAX_JS_SAFE_INT64,
55 EXPECTED_MIN_JS_SAFE_INT64,
56 EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64,
57 EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64,
58 EXPECTED_MAX_SIGNED_INT64,
59 EXPECTED_MIN_SIGNED_INT64
60 ];
61 assert.ok(EXPECTED_SMALL_INT64.equals(Int64Test.SMALL_INT64));
62 assert.ok(EXPECTED_MAX_JS_SAFE_INT64.equals(Int64Test.MAX_JS_SAFE_INT64));
63 assert.ok(EXPECTED_MIN_JS_SAFE_INT64.equals(Int64Test.MIN_JS_SAFE_INT64));
64 assert.ok(
65 EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64.equals(
66 Int64Test.MAX_JS_SAFE_PLUS_ONE_INT64
67 )
68 );
69 assert.ok(
70 EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64.equals(
71 Int64Test.MIN_JS_SAFE_MINUS_ONE_INT64
72 )
73 );
74 assert.ok(EXPECTED_MAX_SIGNED_INT64.equals(Int64Test.MAX_SIGNED_INT64));
75 assert.ok(EXPECTED_MIN_SIGNED_INT64.equals(Int64Test.MIN_SIGNED_INT64));
76 assert.equal(
77 EXPECTED_SMALL_INT64_AS_NUMBER,
78 Int64Test.SMALL_INT64.toNumber()
79 );
80 assert.equal(
81 Number.MAX_SAFE_INTEGER,
82 Int64Test.MAX_JS_SAFE_INT64.toNumber()
83 );
84 assert.equal(
85 Number.MIN_SAFE_INTEGER,
86 Int64Test.MIN_JS_SAFE_INT64.toNumber()
87 );
88
89 for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) {
90 assert.ok(EXPECTED_INT64_LIST[i].equals(Int64Test.INT64_LIST[i]));
91 }
92 console.log('Int64 test -- ends');
93 });
94