diff --git a/package.json b/package.json index ee384d1..8e6e1ee 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,9 @@ "@ljharb/eslint-config": "^21.1.1", "auto-changelog": "^2.5.0", "encoding": "^0.1.13", + "es-value-fixtures": "^1.5.0", "eslint": "=8.8.0", - "has-symbols": "^1.0.3", + "for-each": "^0.3.3", "in-publish": "^2.0.1", "npmignore": "^0.3.1", "nyc": "^10.3.2", diff --git a/test/index.js b/test/index.js index f9ea998..a275157 100644 --- a/test/index.js +++ b/test/index.js @@ -2,32 +2,10 @@ var test = require('tape'); var inspect = require('object-inspect'); -var whichBoxedPrimitive = require('..'); +var forEach = require('for-each'); +var v = require('es-value-fixtures'); -var debug = function (v, m) { return inspect(v) + ' ' + m; }; - -var forEach = function (arr, func) { - var i; - for (i = 0; i < arr.length; ++i) { - func(arr[i], i, arr); - } -}; - -var hasSymbols = require('has-symbols')(); -var hasBigInts = typeof BigInt === 'function'; - -var primitives = [ - true, - false, - 42, - NaN, - Infinity, - '', - 'foo' -].concat( - hasSymbols ? [Symbol(), Symbol.iterator] : [], - hasBigInts ? BigInt(42) : [] -); +var whichBoxedPrimitive = require('../'); var objects = [ /a/g, @@ -35,29 +13,31 @@ var objects = [ function () {}, [], {} -]; +].concat(v.objects); test('isBoxedPrimitive', function (t) { t.test('unboxed primitives', function (st) { - forEach([null, undefined].concat(primitives), function (primitive) { - st.equal(null, whichBoxedPrimitive(primitive), debug(primitive, 'is a primitive, but not a boxed primitive')); + forEach(v.primitives, function (primitive) { + st.equal(null, whichBoxedPrimitive(primitive), inspect(primitive) + ' is a primitive, but not a boxed primitive'); }); st.end(); }); t.test('boxed primitives', function (st) { - forEach(primitives, function (primitive) { - var boxed = Object(primitive); - var expected = boxed.constructor.name; - st.equal(typeof expected, 'string', 'expected is string'); - st.equal(whichBoxedPrimitive(boxed), expected, debug(boxed, 'is a boxed primitive: ' + expected)); + forEach(v.primitives, function (primitive) { + if (primitive != null) { // eslint-disable-line eqeqeq + var boxed = Object(primitive); + var expected = boxed.constructor.name; + st.equal(typeof expected, 'string', 'expected is string'); + st.equal(whichBoxedPrimitive(boxed), expected, inspect(boxed) + ' is a boxed primitive: ' + expected); + } }); st.end(); }); t.test('non-primitive objects', function (st) { forEach(objects, function (object) { - st.equal(undefined, whichBoxedPrimitive(object), debug(object, 'is not a primitive, boxed or otherwise')); + st.equal(undefined, whichBoxedPrimitive(object), inspect(object) + ' is not a primitive, boxed or otherwise'); }); st.end(); });