blob: 106e446b11ef124d8706ad5a8b9d095b0278060c [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
20const Int64 = require("node-int64");
21const i64types = require("./gen-nodejs-es6/Int64Test_types.js");
22const test = require("tape");
23
24const cases = {
25 "should correctly generate Int64 constants": function(assert) {
26 const EXPECTED_SMALL_INT64_AS_NUMBER = 42;
27 const EXPECTED_SMALL_INT64 = new Int64(42);
28 const EXPECTED_MAX_JS_SAFE_INT64 = new Int64(Number.MAX_SAFE_INTEGER);
29 const EXPECTED_MIN_JS_SAFE_INT64 = new Int64(Number.MIN_SAFE_INTEGER);
30 const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64 = new Int64("0020000000000000"); // hex-encoded
31 const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64 = new Int64("ffe0000000000000"); // hex-encoded 2's complement
32 const EXPECTED_MAX_SIGNED_INT64 = new Int64("7fffffffffffffff"); // hex-encoded
33 const EXPECTED_MIN_SIGNED_INT64 = new Int64("8000000000000000"); // hex-encoded 2's complement
34 const EXPECTED_INT64_LIST = [
35 EXPECTED_SMALL_INT64,
36 EXPECTED_MAX_JS_SAFE_INT64,
37 EXPECTED_MIN_JS_SAFE_INT64,
38 EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64,
39 EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64,
40 EXPECTED_MAX_SIGNED_INT64,
41 EXPECTED_MIN_SIGNED_INT64
42 ];
43
44 assert.ok(EXPECTED_SMALL_INT64.equals(i64types.SMALL_INT64));
45 assert.ok(EXPECTED_MAX_JS_SAFE_INT64.equals(i64types.MAX_JS_SAFE_INT64));
46 assert.ok(EXPECTED_MIN_JS_SAFE_INT64.equals(i64types.MIN_JS_SAFE_INT64));
47 assert.ok(
48 EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64.equals(
49 i64types.MAX_JS_SAFE_PLUS_ONE_INT64
50 )
51 );
52 assert.ok(
53 EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64.equals(
54 i64types.MIN_JS_SAFE_MINUS_ONE_INT64
55 )
56 );
57 assert.ok(EXPECTED_MAX_SIGNED_INT64.equals(i64types.MAX_SIGNED_INT64));
58 assert.ok(EXPECTED_MIN_SIGNED_INT64.equals(i64types.MIN_SIGNED_INT64));
59 assert.equal(
60 EXPECTED_SMALL_INT64_AS_NUMBER,
61 i64types.SMALL_INT64.toNumber()
62 );
63 assert.equal(
64 Number.MAX_SAFE_INTEGER,
65 i64types.MAX_JS_SAFE_INT64.toNumber()
66 );
67 assert.equal(
68 Number.MIN_SAFE_INTEGER,
69 i64types.MIN_JS_SAFE_INT64.toNumber()
70 );
71
72 for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) {
73 assert.ok(EXPECTED_INT64_LIST[i].equals(i64types.INT64_LIST[i]));
74 }
75 assert.end();
76 }
77};
78
79Object.keys(cases).forEach(function(caseName) {
80 test(caseName, cases[caseName]);
81});