github-pages-deploy-action/node_modules/es-abstract/test/GetIntrinsic.js

95 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2020-01-28 13:08:03 +08:00
'use strict';
var GetIntrinsic = require('../GetIntrinsic');
var test = require('tape');
var forEach = require('foreach');
var debug = require('object-inspect');
var v = require('./helpers/values');
test('export', function (t) {
t.equal(typeof GetIntrinsic, 'function', 'it is a function');
t.equal(GetIntrinsic.length, 2, 'function has length of 2');
t.end();
});
test('throws', function (t) {
t['throws'](
function () { GetIntrinsic('not an intrinsic'); },
SyntaxError,
'nonexistent intrinsic throws a syntax error'
);
2020-03-07 11:45:40 +08:00
t['throws'](
function () { GetIntrinsic(''); },
TypeError,
'empty string intrinsic throws a type error'
);
t['throws'](
function () { GetIntrinsic('.'); },
SyntaxError,
'"just a dot" intrinsic throws a syntax error'
);
forEach(v.nonStrings, function (nonString) {
t['throws'](
function () { GetIntrinsic(nonString); },
TypeError,
debug(nonString) + ' is not a String'
);
});
2020-01-28 13:08:03 +08:00
forEach(v.nonBooleans, function (nonBoolean) {
t['throws'](
function () { GetIntrinsic('%', nonBoolean); },
TypeError,
debug(nonBoolean) + ' is not a Boolean'
);
});
2020-03-07 11:45:40 +08:00
forEach([
'toString',
'propertyIsEnumerable',
'hasOwnProperty'
], function (objectProtoMember) {
t['throws'](
function () { GetIntrinsic(objectProtoMember); },
SyntaxError,
debug(objectProtoMember) + ' is not an intrinsic'
);
});
2020-01-28 13:08:03 +08:00
t.end();
});
test('base intrinsics', function (t) {
t.equal(GetIntrinsic('%Object%'), Object, '%Object% yields Object');
2020-03-07 11:45:40 +08:00
t.equal(GetIntrinsic('Object'), Object, 'Object yields Object');
2020-01-28 13:08:03 +08:00
t.equal(GetIntrinsic('%Array%'), Array, '%Array% yields Array');
2020-03-07 11:45:40 +08:00
t.equal(GetIntrinsic('Array'), Array, 'Array yields Array');
2020-01-28 13:08:03 +08:00
t.end();
});
test('dotted paths', function (t) {
t.equal(GetIntrinsic('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% yields Object.prototype.toString');
2020-03-07 11:45:40 +08:00
t.equal(GetIntrinsic('Object.prototype.toString'), Object.prototype.toString, 'Object.prototype.toString yields Object.prototype.toString');
2020-01-28 13:08:03 +08:00
t.equal(GetIntrinsic('%Array.prototype.push%'), Array.prototype.push, '%Array.prototype.push% yields Array.prototype.push');
2020-03-07 11:45:40 +08:00
t.equal(GetIntrinsic('Array.prototype.push'), Array.prototype.push, 'Array.prototype.push yields Array.prototype.push');
t.end();
});
test('accessors', { skip: !Object.getOwnPropertyDescriptor || typeof Map !== 'function' }, function (t) {
var actual = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
t.ok(actual, 'Map.prototype.size has a descriptor');
t.equal(typeof actual.get, 'function', 'Map.prototype.size has a getter function');
t.equal(GetIntrinsic('%Map.prototype.size%'), actual.get, '%Map.prototype.size% yields the getter for it');
t.equal(GetIntrinsic('Map.prototype.size'), actual.get, 'Map.prototype.size yields the getter for it');
2020-01-28 13:08:03 +08:00
t.end();
});