1 | 'use strict';
|
---|
2 |
|
---|
3 | var test = require('tape');
|
---|
4 | var debug = require('object-inspect');
|
---|
5 | var forEach = require('for-each');
|
---|
6 | var hasOwn = require('hasown');
|
---|
7 | var v = require('es-value-fixtures');
|
---|
8 |
|
---|
9 | var getSymbolDescription = require('../');
|
---|
10 | var getInferredName = require('../getInferredName');
|
---|
11 |
|
---|
12 | test('getSymbolDescription', function (t) {
|
---|
13 | t.test('no symbols', { skip: v.hasSymbols }, function (st) {
|
---|
14 | st['throws'](
|
---|
15 | getSymbolDescription,
|
---|
16 | SyntaxError,
|
---|
17 | 'requires Symbol support'
|
---|
18 | );
|
---|
19 |
|
---|
20 | st.end();
|
---|
21 | });
|
---|
22 |
|
---|
23 | forEach(v.nonSymbolPrimitives.concat(v.objects), function (nonSymbol) {
|
---|
24 | t['throws'](
|
---|
25 | function () { getSymbolDescription(nonSymbol); },
|
---|
26 | v.hasSymbols ? TypeError : SyntaxError,
|
---|
27 | debug(nonSymbol) + ' is not a Symbol'
|
---|
28 | );
|
---|
29 | });
|
---|
30 |
|
---|
31 | t.test('with symbols', { skip: !v.hasSymbols }, function (st) {
|
---|
32 | forEach(
|
---|
33 | [
|
---|
34 | [Symbol(), undefined],
|
---|
35 | [Symbol(undefined), undefined],
|
---|
36 | [Symbol(null), 'null'],
|
---|
37 | [Symbol.iterator, 'Symbol.iterator'],
|
---|
38 | [Symbol('foo'), 'foo']
|
---|
39 | ],
|
---|
40 | function (pair) {
|
---|
41 | var sym = pair[0];
|
---|
42 | var desc = pair[1];
|
---|
43 | st.equal(getSymbolDescription(sym), desc, debug(sym) + ' description is ' + debug(desc));
|
---|
44 | }
|
---|
45 | );
|
---|
46 |
|
---|
47 | st.test('only possible when inference or native `Symbol.prototype.description` is supported', {
|
---|
48 | skip: !getInferredName && !hasOwn(Symbol.prototype, 'description')
|
---|
49 | }, function (s2t) {
|
---|
50 | s2t.equal(getSymbolDescription(Symbol('')), '', 'Symbol("") description is ""');
|
---|
51 |
|
---|
52 | s2t.end();
|
---|
53 | });
|
---|
54 |
|
---|
55 | st.test('only possible when global symbols are supported', {
|
---|
56 | skip: !hasOwn(Symbol, 'for') || !hasOwn(Symbol, 'keyFor')
|
---|
57 | }, function (s2t) {
|
---|
58 | // eslint-disable-next-line no-restricted-properties
|
---|
59 | s2t.equal(getSymbolDescription(Symbol['for']('')), '', 'Symbol.for("") description is ""');
|
---|
60 | s2t.end();
|
---|
61 | });
|
---|
62 |
|
---|
63 | st.end();
|
---|
64 | });
|
---|
65 |
|
---|
66 | t.end();
|
---|
67 | });
|
---|