[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 | var inspect = require('object-inspect');
|
---|
[79a0317] | 5 | var forEach = require('for-each');
|
---|
| 6 | var v = require('es-value-fixtures');
|
---|
[d565449] | 7 |
|
---|
[79a0317] | 8 | var whichBoxedPrimitive = require('../');
|
---|
[d565449] | 9 |
|
---|
| 10 | var objects = [
|
---|
| 11 | /a/g,
|
---|
| 12 | new Date(),
|
---|
| 13 | function () {},
|
---|
| 14 | [],
|
---|
| 15 | {}
|
---|
[79a0317] | 16 | ].concat(v.objects);
|
---|
[d565449] | 17 |
|
---|
| 18 | test('isBoxedPrimitive', function (t) {
|
---|
| 19 | t.test('unboxed primitives', function (st) {
|
---|
[79a0317] | 20 | forEach(v.primitives, function (primitive) {
|
---|
| 21 | st.equal(null, whichBoxedPrimitive(primitive), inspect(primitive) + ' is a primitive, but not a boxed primitive');
|
---|
[d565449] | 22 | });
|
---|
| 23 | st.end();
|
---|
| 24 | });
|
---|
| 25 |
|
---|
| 26 | t.test('boxed primitives', function (st) {
|
---|
[79a0317] | 27 | forEach(v.primitives, function (primitive) {
|
---|
| 28 | if (primitive != null) { // eslint-disable-line eqeqeq
|
---|
| 29 | var boxed = Object(primitive);
|
---|
| 30 | var expected = boxed.constructor.name;
|
---|
| 31 | st.equal(typeof expected, 'string', 'expected is string');
|
---|
| 32 | st.equal(whichBoxedPrimitive(boxed), expected, inspect(boxed) + ' is a boxed primitive: ' + expected);
|
---|
| 33 | }
|
---|
[d565449] | 34 | });
|
---|
| 35 | st.end();
|
---|
| 36 | });
|
---|
| 37 |
|
---|
| 38 | t.test('non-primitive objects', function (st) {
|
---|
| 39 | forEach(objects, function (object) {
|
---|
[79a0317] | 40 | st.equal(undefined, whichBoxedPrimitive(object), inspect(object) + ' is not a primitive, boxed or otherwise');
|
---|
[d565449] | 41 | });
|
---|
| 42 | st.end();
|
---|
| 43 | });
|
---|
| 44 |
|
---|
| 45 | t.end();
|
---|
| 46 | });
|
---|