Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

asymmetricMatchers.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.stringNotMatching =
  6. exports.stringMatching =
  7. exports.stringNotContaining =
  8. exports.stringContaining =
  9. exports.objectNotContaining =
  10. exports.objectContaining =
  11. exports.arrayNotContaining =
  12. exports.arrayContaining =
  13. exports.anything =
  14. exports.any =
  15. exports.AsymmetricMatcher =
  16. void 0;
  17. var _jasmineUtils = require('./jasmineUtils');
  18. var global = (function () {
  19. if (typeof globalThis !== 'undefined') {
  20. return globalThis;
  21. } else if (typeof global !== 'undefined') {
  22. return global;
  23. } else if (typeof self !== 'undefined') {
  24. return self;
  25. } else if (typeof window !== 'undefined') {
  26. return window;
  27. } else {
  28. return Function('return this')();
  29. }
  30. })();
  31. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  32. function _defineProperty(obj, key, value) {
  33. if (key in obj) {
  34. Object.defineProperty(obj, key, {
  35. value: value,
  36. enumerable: true,
  37. configurable: true,
  38. writable: true
  39. });
  40. } else {
  41. obj[key] = value;
  42. }
  43. return obj;
  44. }
  45. class AsymmetricMatcher {
  46. constructor(sample) {
  47. _defineProperty(this, 'sample', void 0);
  48. _defineProperty(this, '$$typeof', void 0);
  49. _defineProperty(this, 'inverse', void 0);
  50. this.$$typeof = Symbol.for('jest.asymmetricMatcher');
  51. this.sample = sample;
  52. }
  53. }
  54. exports.AsymmetricMatcher = AsymmetricMatcher;
  55. class Any extends AsymmetricMatcher {
  56. constructor(sample) {
  57. if (typeof sample === 'undefined') {
  58. throw new TypeError(
  59. 'any() expects to be passed a constructor function. ' +
  60. 'Please pass one or use anything() to match any object.'
  61. );
  62. }
  63. super(sample);
  64. }
  65. asymmetricMatch(other) {
  66. if (this.sample == String) {
  67. return typeof other == 'string' || other instanceof String;
  68. }
  69. if (this.sample == Number) {
  70. return typeof other == 'number' || other instanceof Number;
  71. }
  72. if (this.sample == Function) {
  73. return typeof other == 'function' || other instanceof Function;
  74. }
  75. if (this.sample == Object) {
  76. return typeof other == 'object';
  77. }
  78. if (this.sample == Boolean) {
  79. return typeof other == 'boolean';
  80. }
  81. /* global BigInt */
  82. if (this.sample == BigInt) {
  83. return typeof other == 'bigint';
  84. }
  85. if (this.sample == Symbol) {
  86. return typeof other == 'symbol';
  87. }
  88. return other instanceof this.sample;
  89. }
  90. toString() {
  91. return 'Any';
  92. }
  93. getExpectedType() {
  94. if (this.sample == String) {
  95. return 'string';
  96. }
  97. if (this.sample == Number) {
  98. return 'number';
  99. }
  100. if (this.sample == Function) {
  101. return 'function';
  102. }
  103. if (this.sample == Object) {
  104. return 'object';
  105. }
  106. if (this.sample == Boolean) {
  107. return 'boolean';
  108. }
  109. return (0, _jasmineUtils.fnNameFor)(this.sample);
  110. }
  111. toAsymmetricMatcher() {
  112. return 'Any<' + (0, _jasmineUtils.fnNameFor)(this.sample) + '>';
  113. }
  114. }
  115. class Anything extends AsymmetricMatcher {
  116. asymmetricMatch(other) {
  117. return !(0, _jasmineUtils.isUndefined)(other) && other !== null;
  118. }
  119. toString() {
  120. return 'Anything';
  121. } // No getExpectedType method, because it matches either null or undefined.
  122. toAsymmetricMatcher() {
  123. return 'Anything';
  124. }
  125. }
  126. class ArrayContaining extends AsymmetricMatcher {
  127. constructor(sample, inverse = false) {
  128. super(sample);
  129. this.inverse = inverse;
  130. }
  131. asymmetricMatch(other) {
  132. if (!Array.isArray(this.sample)) {
  133. throw new Error(
  134. `You must provide an array to ${this.toString()}, not '` +
  135. typeof this.sample +
  136. "'."
  137. );
  138. }
  139. const result =
  140. this.sample.length === 0 ||
  141. (Array.isArray(other) &&
  142. this.sample.every(item =>
  143. other.some(another => (0, _jasmineUtils.equals)(item, another))
  144. ));
  145. return this.inverse ? !result : result;
  146. }
  147. toString() {
  148. return `Array${this.inverse ? 'Not' : ''}Containing`;
  149. }
  150. getExpectedType() {
  151. return 'array';
  152. }
  153. }
  154. class ObjectContaining extends AsymmetricMatcher {
  155. constructor(sample, inverse = false) {
  156. super(sample);
  157. this.inverse = inverse;
  158. }
  159. asymmetricMatch(other) {
  160. if (typeof this.sample !== 'object') {
  161. throw new Error(
  162. `You must provide an object to ${this.toString()}, not '` +
  163. typeof this.sample +
  164. "'."
  165. );
  166. }
  167. let result = true;
  168. for (const property in this.sample) {
  169. if (
  170. !(0, _jasmineUtils.hasProperty)(other, property) ||
  171. !(0, _jasmineUtils.equals)(this.sample[property], other[property])
  172. ) {
  173. result = false;
  174. break;
  175. }
  176. }
  177. return this.inverse ? !result : result;
  178. }
  179. toString() {
  180. return `Object${this.inverse ? 'Not' : ''}Containing`;
  181. }
  182. getExpectedType() {
  183. return 'object';
  184. }
  185. }
  186. class StringContaining extends AsymmetricMatcher {
  187. constructor(sample, inverse = false) {
  188. if (!(0, _jasmineUtils.isA)('String', sample)) {
  189. throw new Error('Expected is not a string');
  190. }
  191. super(sample);
  192. this.inverse = inverse;
  193. }
  194. asymmetricMatch(other) {
  195. const result =
  196. (0, _jasmineUtils.isA)('String', other) && other.includes(this.sample);
  197. return this.inverse ? !result : result;
  198. }
  199. toString() {
  200. return `String${this.inverse ? 'Not' : ''}Containing`;
  201. }
  202. getExpectedType() {
  203. return 'string';
  204. }
  205. }
  206. class StringMatching extends AsymmetricMatcher {
  207. constructor(sample, inverse = false) {
  208. if (
  209. !(0, _jasmineUtils.isA)('String', sample) &&
  210. !(0, _jasmineUtils.isA)('RegExp', sample)
  211. ) {
  212. throw new Error('Expected is not a String or a RegExp');
  213. }
  214. super(new RegExp(sample));
  215. this.inverse = inverse;
  216. }
  217. asymmetricMatch(other) {
  218. const result =
  219. (0, _jasmineUtils.isA)('String', other) && this.sample.test(other);
  220. return this.inverse ? !result : result;
  221. }
  222. toString() {
  223. return `String${this.inverse ? 'Not' : ''}Matching`;
  224. }
  225. getExpectedType() {
  226. return 'string';
  227. }
  228. }
  229. const any = expectedObject => new Any(expectedObject);
  230. exports.any = any;
  231. const anything = () => new Anything();
  232. exports.anything = anything;
  233. const arrayContaining = sample => new ArrayContaining(sample);
  234. exports.arrayContaining = arrayContaining;
  235. const arrayNotContaining = sample => new ArrayContaining(sample, true);
  236. exports.arrayNotContaining = arrayNotContaining;
  237. const objectContaining = sample => new ObjectContaining(sample);
  238. exports.objectContaining = objectContaining;
  239. const objectNotContaining = sample => new ObjectContaining(sample, true);
  240. exports.objectNotContaining = objectNotContaining;
  241. const stringContaining = expected => new StringContaining(expected);
  242. exports.stringContaining = stringContaining;
  243. const stringNotContaining = expected => new StringContaining(expected, true);
  244. exports.stringNotContaining = stringNotContaining;
  245. const stringMatching = expected => new StringMatching(expected);
  246. exports.stringMatching = stringMatching;
  247. const stringNotMatching = expected => new StringMatching(expected, true);
  248. exports.stringNotMatching = stringNotMatching;