[d565449] | 1 | var test = require('tape');
|
---|
| 2 | var v = require('es-value-fixtures');
|
---|
| 3 | var forEach = require('for-each');
|
---|
| 4 |
|
---|
| 5 | var inspect = require('../');
|
---|
| 6 |
|
---|
| 7 | test('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 |
|
---|
| 17 | test('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 | });
|
---|