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.1 KB
|
Line | |
---|
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');
|
---|
7 | var hasSymbols = require('has-symbols')();
|
---|
8 | var hasBigInts = require('has-bigints')();
|
---|
9 |
|
---|
10 | var unboxPrimitive = require('..');
|
---|
11 |
|
---|
12 | var debug = function (v, m) { return inspect(v) + ' ' + m; };
|
---|
13 |
|
---|
14 | test('primitives', function (t) {
|
---|
15 | var primitives = [
|
---|
16 | true,
|
---|
17 | false,
|
---|
18 | '',
|
---|
19 | 'foo',
|
---|
20 | 42,
|
---|
21 | NaN,
|
---|
22 | Infinity,
|
---|
23 | 0
|
---|
24 | ];
|
---|
25 | if (hasSymbols) {
|
---|
26 | primitives.push(Symbol(), Symbol.iterator, Symbol('f'));
|
---|
27 | }
|
---|
28 | if (hasBigInts) {
|
---|
29 | primitives.push(BigInt(42), BigInt(0));
|
---|
30 | }
|
---|
31 | forEach(primitives, function (primitive) {
|
---|
32 | var obj = Object(primitive);
|
---|
33 | t.ok(
|
---|
34 | is(unboxPrimitive(obj), primitive),
|
---|
35 | debug(obj, 'unboxes to ' + inspect(primitive))
|
---|
36 | );
|
---|
37 | });
|
---|
38 |
|
---|
39 | t.end();
|
---|
40 | });
|
---|
41 |
|
---|
42 | test('objects', function (t) {
|
---|
43 | var objects = [
|
---|
44 | {},
|
---|
45 | [],
|
---|
46 | function () {},
|
---|
47 | /a/g,
|
---|
48 | new Date()
|
---|
49 | ];
|
---|
50 | forEach(objects, function (object) {
|
---|
51 | t['throws'](
|
---|
52 | function () { unboxPrimitive(object); },
|
---|
53 | TypeError,
|
---|
54 | debug(object, 'is not a primitive')
|
---|
55 | );
|
---|
56 | });
|
---|
57 |
|
---|
58 | t.end();
|
---|
59 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.