[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 | var inspect = require('object-inspect');
|
---|
| 5 | var is = require('object-is');
|
---|
| 6 | var forEach = require('for-each');
|
---|
[79a0317] | 7 | var v = require('es-value-fixtures');
|
---|
[d565449] | 8 |
|
---|
| 9 | var unboxPrimitive = require('..');
|
---|
| 10 |
|
---|
| 11 | test('primitives', function (t) {
|
---|
[79a0317] | 12 | forEach([null, undefined], function (nullValue) {
|
---|
| 13 | t['throws'](
|
---|
| 14 | // @ts-expect-error
|
---|
| 15 | function () { unboxPrimitive(nullValue); },
|
---|
| 16 | TypeError,
|
---|
| 17 | inspect(nullValue) + ' is not a primitive'
|
---|
| 18 | );
|
---|
| 19 | });
|
---|
| 20 |
|
---|
| 21 | // eslint-disable-next-line no-extra-parens
|
---|
| 22 | forEach(/** @type {typeof v.nonNullPrimitives} */ ([].concat(
|
---|
| 23 | // @ts-expect-error TS sucks with concat
|
---|
| 24 | v.nonNullPrimitives,
|
---|
| 25 | v.zeroes,
|
---|
| 26 | v.infinities,
|
---|
| 27 | NaN
|
---|
| 28 | )), function (primitive) {
|
---|
[d565449] | 29 | var obj = Object(primitive);
|
---|
| 30 | t.ok(
|
---|
| 31 | is(unboxPrimitive(obj), primitive),
|
---|
[79a0317] | 32 | inspect(obj) + 'unboxes to ' + inspect(primitive)
|
---|
[d565449] | 33 | );
|
---|
| 34 | });
|
---|
| 35 |
|
---|
| 36 | t.end();
|
---|
| 37 | });
|
---|
| 38 |
|
---|
| 39 | test('objects', function (t) {
|
---|
[79a0317] | 40 | // eslint-disable-next-line no-extra-parens
|
---|
| 41 | forEach(/** @type {typeof v.objects} */ (/** @type {unknown} */ ([].concat(
|
---|
| 42 | // @ts-expect-error TS sucks with concat
|
---|
| 43 | v.objects,
|
---|
[d565449] | 44 | {},
|
---|
| 45 | [],
|
---|
| 46 | function () {},
|
---|
| 47 | /a/g,
|
---|
| 48 | new Date()
|
---|
[79a0317] | 49 | ))), function (object) {
|
---|
[d565449] | 50 | t['throws'](
|
---|
[79a0317] | 51 | // @ts-expect-error
|
---|
[d565449] | 52 | function () { unboxPrimitive(object); },
|
---|
| 53 | TypeError,
|
---|
[79a0317] | 54 | inspect(object) + ' is not a primitive'
|
---|
[d565449] | 55 | );
|
---|
| 56 | });
|
---|
| 57 |
|
---|
| 58 | t.end();
|
---|
| 59 | });
|
---|