1
|
'use strict';
|
2
|
|
3
|
var GetIntrinsic = require('../GetIntrinsic');
|
4
|
|
5
|
var test = require('tape');
|
6
|
var forEach = require('foreach');
|
7
|
var debug = require('object-inspect');
|
8
|
|
9
|
var v = require('./helpers/values');
|
10
|
|
11
|
test('export', function (t) {
|
12
|
t.equal(typeof GetIntrinsic, 'function', 'it is a function');
|
13
|
t.equal(GetIntrinsic.length, 2, 'function has length of 2');
|
14
|
|
15
|
t.end();
|
16
|
});
|
17
|
|
18
|
test('throws', function (t) {
|
19
|
t['throws'](
|
20
|
function () { GetIntrinsic('not an intrinsic'); },
|
21
|
SyntaxError,
|
22
|
'nonexistent intrinsic throws a syntax error'
|
23
|
);
|
24
|
|
25
|
t['throws'](
|
26
|
function () { GetIntrinsic(''); },
|
27
|
TypeError,
|
28
|
'empty string intrinsic throws a type error'
|
29
|
);
|
30
|
|
31
|
t['throws'](
|
32
|
function () { GetIntrinsic('.'); },
|
33
|
SyntaxError,
|
34
|
'"just a dot" intrinsic throws a syntax error'
|
35
|
);
|
36
|
|
37
|
forEach(v.nonStrings, function (nonString) {
|
38
|
t['throws'](
|
39
|
function () { GetIntrinsic(nonString); },
|
40
|
TypeError,
|
41
|
debug(nonString) + ' is not a String'
|
42
|
);
|
43
|
});
|
44
|
|
45
|
forEach(v.nonBooleans, function (nonBoolean) {
|
46
|
t['throws'](
|
47
|
function () { GetIntrinsic('%', nonBoolean); },
|
48
|
TypeError,
|
49
|
debug(nonBoolean) + ' is not a Boolean'
|
50
|
);
|
51
|
});
|
52
|
|
53
|
forEach([
|
54
|
'toString',
|
55
|
'propertyIsEnumerable',
|
56
|
'hasOwnProperty'
|
57
|
], function (objectProtoMember) {
|
58
|
t['throws'](
|
59
|
function () { GetIntrinsic(objectProtoMember); },
|
60
|
SyntaxError,
|
61
|
debug(objectProtoMember) + ' is not an intrinsic'
|
62
|
);
|
63
|
});
|
64
|
|
65
|
t.end();
|
66
|
});
|
67
|
|
68
|
test('base intrinsics', function (t) {
|
69
|
t.equal(GetIntrinsic('%Object%'), Object, '%Object% yields Object');
|
70
|
t.equal(GetIntrinsic('Object'), Object, 'Object yields Object');
|
71
|
t.equal(GetIntrinsic('%Array%'), Array, '%Array% yields Array');
|
72
|
t.equal(GetIntrinsic('Array'), Array, 'Array yields Array');
|
73
|
|
74
|
t.end();
|
75
|
});
|
76
|
|
77
|
test('dotted paths', function (t) {
|
78
|
t.equal(GetIntrinsic('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% yields Object.prototype.toString');
|
79
|
t.equal(GetIntrinsic('Object.prototype.toString'), Object.prototype.toString, 'Object.prototype.toString yields Object.prototype.toString');
|
80
|
t.equal(GetIntrinsic('%Array.prototype.push%'), Array.prototype.push, '%Array.prototype.push% yields Array.prototype.push');
|
81
|
t.equal(GetIntrinsic('Array.prototype.push'), Array.prototype.push, 'Array.prototype.push yields Array.prototype.push');
|
82
|
|
83
|
t.end();
|
84
|
});
|
85
|
|
86
|
test('accessors', { skip: !Object.getOwnPropertyDescriptor || typeof Map !== 'function' }, function (t) {
|
87
|
var actual = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
|
88
|
t.ok(actual, 'Map.prototype.size has a descriptor');
|
89
|
t.equal(typeof actual.get, 'function', 'Map.prototype.size has a getter function');
|
90
|
t.equal(GetIntrinsic('%Map.prototype.size%'), actual.get, '%Map.prototype.size% yields the getter for it');
|
91
|
t.equal(GetIntrinsic('Map.prototype.size'), actual.get, 'Map.prototype.size yields the getter for it');
|
92
|
|
93
|
t.end();
|
94
|
});
|