source: imaps-frontend/node_modules/which-boxed-primitive/test/index.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: 1.5 KB
Line 
1'use strict';
2
3var test = require('tape');
4var inspect = require('object-inspect');
5var whichBoxedPrimitive = require('..');
6
7var debug = function (v, m) { return inspect(v) + ' ' + m; };
8
9var forEach = function (arr, func) {
10 var i;
11 for (i = 0; i < arr.length; ++i) {
12 func(arr[i], i, arr);
13 }
14};
15
16var hasSymbols = require('has-symbols')();
17var hasBigInts = typeof BigInt === 'function';
18
19var primitives = [
20 true,
21 false,
22 42,
23 NaN,
24 Infinity,
25 '',
26 'foo'
27].concat(
28 hasSymbols ? [Symbol(), Symbol.iterator] : [],
29 hasBigInts ? BigInt(42) : []
30);
31
32var objects = [
33 /a/g,
34 new Date(),
35 function () {},
36 [],
37 {}
38];
39
40test('isBoxedPrimitive', function (t) {
41 t.test('unboxed primitives', function (st) {
42 forEach([null, undefined].concat(primitives), function (primitive) {
43 st.equal(null, whichBoxedPrimitive(primitive), debug(primitive, 'is a primitive, but not a boxed primitive'));
44 });
45 st.end();
46 });
47
48 t.test('boxed primitives', function (st) {
49 forEach(primitives, function (primitive) {
50 var boxed = Object(primitive);
51 var expected = boxed.constructor.name;
52 st.equal(typeof expected, 'string', 'expected is string');
53 st.equal(whichBoxedPrimitive(boxed), expected, debug(boxed, 'is a boxed primitive: ' + expected));
54 });
55 st.end();
56 });
57
58 t.test('non-primitive objects', function (st) {
59 forEach(objects, function (object) {
60 st.equal(undefined, whichBoxedPrimitive(object), debug(object, 'is not a primitive, boxed or otherwise'));
61 });
62 st.end();
63 });
64
65 t.end();
66});
Note: See TracBrowser for help on using the repository browser.