Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GetIntrinsic.js 2.8KB

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