source: imaps-frontend/node_modules/object-inspect/test/number.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[d565449]1var test = require('tape');
2var v = require('es-value-fixtures');
3var forEach = require('for-each');
4
5var inspect = require('../');
6
7test('negative zero', function (t) {
8 t.equal(inspect(0), '0', 'inspect(0) === "0"');
9 t.equal(inspect(Object(0)), 'Object(0)', 'inspect(Object(0)) === "Object(0)"');
10
11 t.equal(inspect(-0), '-0', 'inspect(-0) === "-0"');
12 t.equal(inspect(Object(-0)), 'Object(-0)', 'inspect(Object(-0)) === "Object(-0)"');
13
14 t.end();
15});
16
17test('numericSeparator', function (t) {
18 forEach(v.nonBooleans, function (nonBoolean) {
19 t['throws'](
20 function () { inspect(true, { numericSeparator: nonBoolean }); },
21 TypeError,
22 inspect(nonBoolean) + ' is not a boolean'
23 );
24 });
25
26 t.test('3 digit numbers', function (st) {
27 var failed = false;
28 for (var i = -999; i < 1000; i += 1) {
29 var actual = inspect(i);
30 var actualSepNo = inspect(i, { numericSeparator: false });
31 var actualSepYes = inspect(i, { numericSeparator: true });
32 var expected = String(i);
33 if (actual !== expected || actualSepNo !== expected || actualSepYes !== expected) {
34 failed = true;
35 t.equal(actual, expected);
36 t.equal(actualSepNo, expected);
37 t.equal(actualSepYes, expected);
38 }
39 }
40
41 st.notOk(failed, 'all 3 digit numbers passed');
42
43 st.end();
44 });
45
46 t.equal(inspect(1e3), '1000', '1000');
47 t.equal(inspect(1e3, { numericSeparator: false }), '1000', '1000, numericSeparator false');
48 t.equal(inspect(1e3, { numericSeparator: true }), '1_000', '1000, numericSeparator true');
49 t.equal(inspect(-1e3), '-1000', '-1000');
50 t.equal(inspect(-1e3, { numericSeparator: false }), '-1000', '-1000, numericSeparator false');
51 t.equal(inspect(-1e3, { numericSeparator: true }), '-1_000', '-1000, numericSeparator true');
52
53 t.equal(inspect(1234.5678, { numericSeparator: true }), '1_234.567_8', 'fractional numbers get separators');
54 t.equal(inspect(1234.56789, { numericSeparator: true }), '1_234.567_89', 'fractional numbers get separators');
55 t.equal(inspect(1234.567891, { numericSeparator: true }), '1_234.567_891', 'fractional numbers get separators');
56
57 t.end();
58});
Note: See TracBrowser for help on using the repository browser.