| [9af201e] | 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var test = require('tape');
|
|---|
| 4 | var inspect = require('object-inspect');
|
|---|
| 5 | var forEach = require('for-each');
|
|---|
| 6 | var v = require('es-value-fixtures');
|
|---|
| 7 |
|
|---|
| 8 | var whichBoxedPrimitive = require('../');
|
|---|
| 9 |
|
|---|
| 10 | var objects = [
|
|---|
| 11 | /a/g,
|
|---|
| 12 | new Date(),
|
|---|
| 13 | function () {},
|
|---|
| 14 | [],
|
|---|
| 15 | {}
|
|---|
| 16 | ].concat(v.objects);
|
|---|
| 17 |
|
|---|
| 18 | test('isBoxedPrimitive', function (t) {
|
|---|
| 19 | t.test('unboxed primitives', function (st) {
|
|---|
| 20 | forEach(v.primitives, function (primitive) {
|
|---|
| 21 | st.equal(null, whichBoxedPrimitive(primitive), inspect(primitive) + ' is a primitive, but not a boxed primitive');
|
|---|
| 22 | });
|
|---|
| 23 | st.end();
|
|---|
| 24 | });
|
|---|
| 25 |
|
|---|
| 26 | t.test('boxed primitives', function (st) {
|
|---|
| 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 | }
|
|---|
| 34 | });
|
|---|
| 35 | st.end();
|
|---|
| 36 | });
|
|---|
| 37 |
|
|---|
| 38 | t.test('non-primitive objects', function (st) {
|
|---|
| 39 | forEach(objects, function (object) {
|
|---|
| 40 | st.equal(undefined, whichBoxedPrimitive(object), inspect(object) + ' is not a primitive, boxed or otherwise');
|
|---|
| 41 | });
|
|---|
| 42 | st.end();
|
|---|
| 43 | });
|
|---|
| 44 |
|
|---|
| 45 | t.end();
|
|---|
| 46 | });
|
|---|