forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-internal-util-toInteger.js
More file actions
32 lines (27 loc) · 928 Bytes
/
Copy pathtest-internal-util-toInteger.js
File metadata and controls
32 lines (27 loc) · 928 Bytes
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
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const {toInteger} = require('internal/util');
const expectZero = [
'0', '-0', NaN, {}, [], {'a': 'b'}, [1, 2], '0x', '0o', '0b', false,
'', ' ', undefined, null
];
expectZero.forEach(function(value) {
assert.strictEqual(toInteger(value), 0);
});
assert.strictEqual(toInteger(Infinity), Infinity);
assert.strictEqual(toInteger(-Infinity), -Infinity);
const expectSame = [
'0x100', '0o100', '0b100', 0x100, -0x100, 0o100, -0o100, 0b100, -0b100, true
];
expectSame.forEach(function(value) {
assert.strictEqual(toInteger(value), +value, `${value} is not an Integer`);
});
const expectIntegers = new Map([
[[1], 1], [[-1], -1], [['1'], 1], [['-1'], -1],
[3.14, 3], [-3.14, -3], ['3.14', 3], ['-3.14', -3],
]);
expectIntegers.forEach(function(expected, value) {
assert.strictEqual(toInteger(value), expected);
});