assert.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. // Currently in sync with Node.js lib/assert.js
  2. // https://github.com/nodejs/node/commit/2a51ae424a513ec9a6aa3466baa0cc1d55dd4f3b
  3. // Originally from narwhal.js (http://narwhaljs.org)
  4. // Copyright (c) 2009 Thomas Robinson <280north.com>
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the 'Software'), to
  8. // deal in the Software without restriction, including without limitation the
  9. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. // sell copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. 'use strict';
  23. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  24. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
  25. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  26. function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
  27. function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
  28. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29. var _require = require('./internal/errors'),
  30. _require$codes = _require.codes,
  31. ERR_AMBIGUOUS_ARGUMENT = _require$codes.ERR_AMBIGUOUS_ARGUMENT,
  32. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  33. ERR_INVALID_ARG_VALUE = _require$codes.ERR_INVALID_ARG_VALUE,
  34. ERR_INVALID_RETURN_VALUE = _require$codes.ERR_INVALID_RETURN_VALUE,
  35. ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS;
  36. var AssertionError = require('./internal/assert/assertion_error');
  37. var _require2 = require('util/'),
  38. inspect = _require2.inspect;
  39. var _require$types = require('util/').types,
  40. isPromise = _require$types.isPromise,
  41. isRegExp = _require$types.isRegExp;
  42. var objectAssign = require('object.assign/polyfill')();
  43. var objectIs = require('object-is/polyfill')();
  44. var RegExpPrototypeTest = require('call-bind/callBound')('RegExp.prototype.test');
  45. var errorCache = new Map();
  46. var isDeepEqual;
  47. var isDeepStrictEqual;
  48. var parseExpressionAt;
  49. var findNodeAround;
  50. var decoder;
  51. function lazyLoadComparison() {
  52. var comparison = require('./internal/util/comparisons');
  53. isDeepEqual = comparison.isDeepEqual;
  54. isDeepStrictEqual = comparison.isDeepStrictEqual;
  55. }
  56. // Escape control characters but not \n and \t to keep the line breaks and
  57. // indentation intact.
  58. // eslint-disable-next-line no-control-regex
  59. var escapeSequencesRegExp = /[\x00-\x08\x0b\x0c\x0e-\x1f]/g;
  60. var meta = ["\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005", "\\u0006", "\\u0007", '\\b', '', '', "\\u000b", '\\f', '', "\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012", "\\u0013", "\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019", "\\u001a", "\\u001b", "\\u001c", "\\u001d", "\\u001e", "\\u001f"];
  61. var escapeFn = function escapeFn(str) {
  62. return meta[str.charCodeAt(0)];
  63. };
  64. var warned = false;
  65. // The assert module provides functions that throw
  66. // AssertionError's when particular conditions are not met. The
  67. // assert module must conform to the following interface.
  68. var assert = module.exports = ok;
  69. var NO_EXCEPTION_SENTINEL = {};
  70. // All of the following functions must throw an AssertionError
  71. // when a corresponding condition is not met, with a message that
  72. // may be undefined if not provided. All assertion methods provide
  73. // both the actual and expected values to the assertion error for
  74. // display purposes.
  75. function innerFail(obj) {
  76. if (obj.message instanceof Error) throw obj.message;
  77. throw new AssertionError(obj);
  78. }
  79. function fail(actual, expected, message, operator, stackStartFn) {
  80. var argsLen = arguments.length;
  81. var internalMessage;
  82. if (argsLen === 0) {
  83. internalMessage = 'Failed';
  84. } else if (argsLen === 1) {
  85. message = actual;
  86. actual = undefined;
  87. } else {
  88. if (warned === false) {
  89. warned = true;
  90. var warn = process.emitWarning ? process.emitWarning : console.warn.bind(console);
  91. warn('assert.fail() with more than one argument is deprecated. ' + 'Please use assert.strictEqual() instead or only pass a message.', 'DeprecationWarning', 'DEP0094');
  92. }
  93. if (argsLen === 2) operator = '!=';
  94. }
  95. if (message instanceof Error) throw message;
  96. var errArgs = {
  97. actual: actual,
  98. expected: expected,
  99. operator: operator === undefined ? 'fail' : operator,
  100. stackStartFn: stackStartFn || fail
  101. };
  102. if (message !== undefined) {
  103. errArgs.message = message;
  104. }
  105. var err = new AssertionError(errArgs);
  106. if (internalMessage) {
  107. err.message = internalMessage;
  108. err.generatedMessage = true;
  109. }
  110. throw err;
  111. }
  112. assert.fail = fail;
  113. // The AssertionError is defined in internal/error.
  114. assert.AssertionError = AssertionError;
  115. function innerOk(fn, argLen, value, message) {
  116. if (!value) {
  117. var generatedMessage = false;
  118. if (argLen === 0) {
  119. generatedMessage = true;
  120. message = 'No value argument passed to `assert.ok()`';
  121. } else if (message instanceof Error) {
  122. throw message;
  123. }
  124. var err = new AssertionError({
  125. actual: value,
  126. expected: true,
  127. message: message,
  128. operator: '==',
  129. stackStartFn: fn
  130. });
  131. err.generatedMessage = generatedMessage;
  132. throw err;
  133. }
  134. }
  135. // Pure assertion tests whether a value is truthy, as determined
  136. // by !!value.
  137. function ok() {
  138. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  139. args[_key] = arguments[_key];
  140. }
  141. innerOk.apply(void 0, [ok, args.length].concat(args));
  142. }
  143. assert.ok = ok;
  144. // The equality assertion tests shallow, coercive equality with ==.
  145. /* eslint-disable no-restricted-properties */
  146. assert.equal = function equal(actual, expected, message) {
  147. if (arguments.length < 2) {
  148. throw new ERR_MISSING_ARGS('actual', 'expected');
  149. }
  150. // eslint-disable-next-line eqeqeq
  151. if (actual != expected) {
  152. innerFail({
  153. actual: actual,
  154. expected: expected,
  155. message: message,
  156. operator: '==',
  157. stackStartFn: equal
  158. });
  159. }
  160. };
  161. // The non-equality assertion tests for whether two objects are not
  162. // equal with !=.
  163. assert.notEqual = function notEqual(actual, expected, message) {
  164. if (arguments.length < 2) {
  165. throw new ERR_MISSING_ARGS('actual', 'expected');
  166. }
  167. // eslint-disable-next-line eqeqeq
  168. if (actual == expected) {
  169. innerFail({
  170. actual: actual,
  171. expected: expected,
  172. message: message,
  173. operator: '!=',
  174. stackStartFn: notEqual
  175. });
  176. }
  177. };
  178. // The equivalence assertion tests a deep equality relation.
  179. assert.deepEqual = function deepEqual(actual, expected, message) {
  180. if (arguments.length < 2) {
  181. throw new ERR_MISSING_ARGS('actual', 'expected');
  182. }
  183. if (isDeepEqual === undefined) lazyLoadComparison();
  184. if (!isDeepEqual(actual, expected)) {
  185. innerFail({
  186. actual: actual,
  187. expected: expected,
  188. message: message,
  189. operator: 'deepEqual',
  190. stackStartFn: deepEqual
  191. });
  192. }
  193. };
  194. // The non-equivalence assertion tests for any deep inequality.
  195. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  196. if (arguments.length < 2) {
  197. throw new ERR_MISSING_ARGS('actual', 'expected');
  198. }
  199. if (isDeepEqual === undefined) lazyLoadComparison();
  200. if (isDeepEqual(actual, expected)) {
  201. innerFail({
  202. actual: actual,
  203. expected: expected,
  204. message: message,
  205. operator: 'notDeepEqual',
  206. stackStartFn: notDeepEqual
  207. });
  208. }
  209. };
  210. /* eslint-enable */
  211. assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
  212. if (arguments.length < 2) {
  213. throw new ERR_MISSING_ARGS('actual', 'expected');
  214. }
  215. if (isDeepEqual === undefined) lazyLoadComparison();
  216. if (!isDeepStrictEqual(actual, expected)) {
  217. innerFail({
  218. actual: actual,
  219. expected: expected,
  220. message: message,
  221. operator: 'deepStrictEqual',
  222. stackStartFn: deepStrictEqual
  223. });
  224. }
  225. };
  226. assert.notDeepStrictEqual = notDeepStrictEqual;
  227. function notDeepStrictEqual(actual, expected, message) {
  228. if (arguments.length < 2) {
  229. throw new ERR_MISSING_ARGS('actual', 'expected');
  230. }
  231. if (isDeepEqual === undefined) lazyLoadComparison();
  232. if (isDeepStrictEqual(actual, expected)) {
  233. innerFail({
  234. actual: actual,
  235. expected: expected,
  236. message: message,
  237. operator: 'notDeepStrictEqual',
  238. stackStartFn: notDeepStrictEqual
  239. });
  240. }
  241. }
  242. assert.strictEqual = function strictEqual(actual, expected, message) {
  243. if (arguments.length < 2) {
  244. throw new ERR_MISSING_ARGS('actual', 'expected');
  245. }
  246. if (!objectIs(actual, expected)) {
  247. innerFail({
  248. actual: actual,
  249. expected: expected,
  250. message: message,
  251. operator: 'strictEqual',
  252. stackStartFn: strictEqual
  253. });
  254. }
  255. };
  256. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  257. if (arguments.length < 2) {
  258. throw new ERR_MISSING_ARGS('actual', 'expected');
  259. }
  260. if (objectIs(actual, expected)) {
  261. innerFail({
  262. actual: actual,
  263. expected: expected,
  264. message: message,
  265. operator: 'notStrictEqual',
  266. stackStartFn: notStrictEqual
  267. });
  268. }
  269. };
  270. var Comparison = /*#__PURE__*/_createClass(function Comparison(obj, keys, actual) {
  271. var _this = this;
  272. _classCallCheck(this, Comparison);
  273. keys.forEach(function (key) {
  274. if (key in obj) {
  275. if (actual !== undefined && typeof actual[key] === 'string' && isRegExp(obj[key]) && RegExpPrototypeTest(obj[key], actual[key])) {
  276. _this[key] = actual[key];
  277. } else {
  278. _this[key] = obj[key];
  279. }
  280. }
  281. });
  282. });
  283. function compareExceptionKey(actual, expected, key, message, keys, fn) {
  284. if (!(key in actual) || !isDeepStrictEqual(actual[key], expected[key])) {
  285. if (!message) {
  286. // Create placeholder objects to create a nice output.
  287. var a = new Comparison(actual, keys);
  288. var b = new Comparison(expected, keys, actual);
  289. var err = new AssertionError({
  290. actual: a,
  291. expected: b,
  292. operator: 'deepStrictEqual',
  293. stackStartFn: fn
  294. });
  295. err.actual = actual;
  296. err.expected = expected;
  297. err.operator = fn.name;
  298. throw err;
  299. }
  300. innerFail({
  301. actual: actual,
  302. expected: expected,
  303. message: message,
  304. operator: fn.name,
  305. stackStartFn: fn
  306. });
  307. }
  308. }
  309. function expectedException(actual, expected, msg, fn) {
  310. if (typeof expected !== 'function') {
  311. if (isRegExp(expected)) return RegExpPrototypeTest(expected, actual);
  312. // assert.doesNotThrow does not accept objects.
  313. if (arguments.length === 2) {
  314. throw new ERR_INVALID_ARG_TYPE('expected', ['Function', 'RegExp'], expected);
  315. }
  316. // Handle primitives properly.
  317. if (_typeof(actual) !== 'object' || actual === null) {
  318. var err = new AssertionError({
  319. actual: actual,
  320. expected: expected,
  321. message: msg,
  322. operator: 'deepStrictEqual',
  323. stackStartFn: fn
  324. });
  325. err.operator = fn.name;
  326. throw err;
  327. }
  328. var keys = Object.keys(expected);
  329. // Special handle errors to make sure the name and the message are compared
  330. // as well.
  331. if (expected instanceof Error) {
  332. keys.push('name', 'message');
  333. } else if (keys.length === 0) {
  334. throw new ERR_INVALID_ARG_VALUE('error', expected, 'may not be an empty object');
  335. }
  336. if (isDeepEqual === undefined) lazyLoadComparison();
  337. keys.forEach(function (key) {
  338. if (typeof actual[key] === 'string' && isRegExp(expected[key]) && RegExpPrototypeTest(expected[key], actual[key])) {
  339. return;
  340. }
  341. compareExceptionKey(actual, expected, key, msg, keys, fn);
  342. });
  343. return true;
  344. }
  345. // Guard instanceof against arrow functions as they don't have a prototype.
  346. if (expected.prototype !== undefined && actual instanceof expected) {
  347. return true;
  348. }
  349. if (Error.isPrototypeOf(expected)) {
  350. return false;
  351. }
  352. return expected.call({}, actual) === true;
  353. }
  354. function getActual(fn) {
  355. if (typeof fn !== 'function') {
  356. throw new ERR_INVALID_ARG_TYPE('fn', 'Function', fn);
  357. }
  358. try {
  359. fn();
  360. } catch (e) {
  361. return e;
  362. }
  363. return NO_EXCEPTION_SENTINEL;
  364. }
  365. function checkIsPromise(obj) {
  366. // Accept native ES6 promises and promises that are implemented in a similar
  367. // way. Do not accept thenables that use a function as `obj` and that have no
  368. // `catch` handler.
  369. // TODO: thenables are checked up until they have the correct methods,
  370. // but according to documentation, the `then` method should receive
  371. // the `fulfill` and `reject` arguments as well or it may be never resolved.
  372. return isPromise(obj) || obj !== null && _typeof(obj) === 'object' && typeof obj.then === 'function' && typeof obj.catch === 'function';
  373. }
  374. function waitForActual(promiseFn) {
  375. return Promise.resolve().then(function () {
  376. var resultPromise;
  377. if (typeof promiseFn === 'function') {
  378. // Return a rejected promise if `promiseFn` throws synchronously.
  379. resultPromise = promiseFn();
  380. // Fail in case no promise is returned.
  381. if (!checkIsPromise(resultPromise)) {
  382. throw new ERR_INVALID_RETURN_VALUE('instance of Promise', 'promiseFn', resultPromise);
  383. }
  384. } else if (checkIsPromise(promiseFn)) {
  385. resultPromise = promiseFn;
  386. } else {
  387. throw new ERR_INVALID_ARG_TYPE('promiseFn', ['Function', 'Promise'], promiseFn);
  388. }
  389. return Promise.resolve().then(function () {
  390. return resultPromise;
  391. }).then(function () {
  392. return NO_EXCEPTION_SENTINEL;
  393. }).catch(function (e) {
  394. return e;
  395. });
  396. });
  397. }
  398. function expectsError(stackStartFn, actual, error, message) {
  399. if (typeof error === 'string') {
  400. if (arguments.length === 4) {
  401. throw new ERR_INVALID_ARG_TYPE('error', ['Object', 'Error', 'Function', 'RegExp'], error);
  402. }
  403. if (_typeof(actual) === 'object' && actual !== null) {
  404. if (actual.message === error) {
  405. throw new ERR_AMBIGUOUS_ARGUMENT('error/message', "The error message \"".concat(actual.message, "\" is identical to the message."));
  406. }
  407. } else if (actual === error) {
  408. throw new ERR_AMBIGUOUS_ARGUMENT('error/message', "The error \"".concat(actual, "\" is identical to the message."));
  409. }
  410. message = error;
  411. error = undefined;
  412. } else if (error != null && _typeof(error) !== 'object' && typeof error !== 'function') {
  413. throw new ERR_INVALID_ARG_TYPE('error', ['Object', 'Error', 'Function', 'RegExp'], error);
  414. }
  415. if (actual === NO_EXCEPTION_SENTINEL) {
  416. var details = '';
  417. if (error && error.name) {
  418. details += " (".concat(error.name, ")");
  419. }
  420. details += message ? ": ".concat(message) : '.';
  421. var fnType = stackStartFn.name === 'rejects' ? 'rejection' : 'exception';
  422. innerFail({
  423. actual: undefined,
  424. expected: error,
  425. operator: stackStartFn.name,
  426. message: "Missing expected ".concat(fnType).concat(details),
  427. stackStartFn: stackStartFn
  428. });
  429. }
  430. if (error && !expectedException(actual, error, message, stackStartFn)) {
  431. throw actual;
  432. }
  433. }
  434. function expectsNoError(stackStartFn, actual, error, message) {
  435. if (actual === NO_EXCEPTION_SENTINEL) return;
  436. if (typeof error === 'string') {
  437. message = error;
  438. error = undefined;
  439. }
  440. if (!error || expectedException(actual, error)) {
  441. var details = message ? ": ".concat(message) : '.';
  442. var fnType = stackStartFn.name === 'doesNotReject' ? 'rejection' : 'exception';
  443. innerFail({
  444. actual: actual,
  445. expected: error,
  446. operator: stackStartFn.name,
  447. message: "Got unwanted ".concat(fnType).concat(details, "\n") + "Actual message: \"".concat(actual && actual.message, "\""),
  448. stackStartFn: stackStartFn
  449. });
  450. }
  451. throw actual;
  452. }
  453. assert.throws = function throws(promiseFn) {
  454. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  455. args[_key2 - 1] = arguments[_key2];
  456. }
  457. expectsError.apply(void 0, [throws, getActual(promiseFn)].concat(args));
  458. };
  459. assert.rejects = function rejects(promiseFn) {
  460. for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  461. args[_key3 - 1] = arguments[_key3];
  462. }
  463. return waitForActual(promiseFn).then(function (result) {
  464. return expectsError.apply(void 0, [rejects, result].concat(args));
  465. });
  466. };
  467. assert.doesNotThrow = function doesNotThrow(fn) {
  468. for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
  469. args[_key4 - 1] = arguments[_key4];
  470. }
  471. expectsNoError.apply(void 0, [doesNotThrow, getActual(fn)].concat(args));
  472. };
  473. assert.doesNotReject = function doesNotReject(fn) {
  474. for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
  475. args[_key5 - 1] = arguments[_key5];
  476. }
  477. return waitForActual(fn).then(function (result) {
  478. return expectsNoError.apply(void 0, [doesNotReject, result].concat(args));
  479. });
  480. };
  481. assert.ifError = function ifError(err) {
  482. if (err !== null && err !== undefined) {
  483. var message = 'ifError got unwanted exception: ';
  484. if (_typeof(err) === 'object' && typeof err.message === 'string') {
  485. if (err.message.length === 0 && err.constructor) {
  486. message += err.constructor.name;
  487. } else {
  488. message += err.message;
  489. }
  490. } else {
  491. message += inspect(err);
  492. }
  493. var newErr = new AssertionError({
  494. actual: err,
  495. expected: null,
  496. operator: 'ifError',
  497. message: message,
  498. stackStartFn: ifError
  499. });
  500. // Make sure we actually have a stack trace!
  501. var origStack = err.stack;
  502. if (typeof origStack === 'string') {
  503. // This will remove any duplicated frames from the error frames taken
  504. // from within `ifError` and add the original error frames to the newly
  505. // created ones.
  506. var tmp2 = origStack.split('\n');
  507. tmp2.shift();
  508. // Filter all frames existing in err.stack.
  509. var tmp1 = newErr.stack.split('\n');
  510. for (var i = 0; i < tmp2.length; i++) {
  511. // Find the first occurrence of the frame.
  512. var pos = tmp1.indexOf(tmp2[i]);
  513. if (pos !== -1) {
  514. // Only keep new frames.
  515. tmp1 = tmp1.slice(0, pos);
  516. break;
  517. }
  518. }
  519. newErr.stack = "".concat(tmp1.join('\n'), "\n").concat(tmp2.join('\n'));
  520. }
  521. throw newErr;
  522. }
  523. };
  524. // Currently in sync with Node.js lib/assert.js
  525. // https://github.com/nodejs/node/commit/2a871df3dfb8ea663ef5e1f8f62701ec51384ecb
  526. function internalMatch(string, regexp, message, fn, fnName) {
  527. if (!isRegExp(regexp)) {
  528. throw new ERR_INVALID_ARG_TYPE('regexp', 'RegExp', regexp);
  529. }
  530. var match = fnName === 'match';
  531. if (typeof string !== 'string' || RegExpPrototypeTest(regexp, string) !== match) {
  532. if (message instanceof Error) {
  533. throw message;
  534. }
  535. var generatedMessage = !message;
  536. // 'The input was expected to not match the regular expression ' +
  537. message = message || (typeof string !== 'string' ? 'The "string" argument must be of type string. Received type ' + "".concat(_typeof(string), " (").concat(inspect(string), ")") : (match ? 'The input did not match the regular expression ' : 'The input was expected to not match the regular expression ') + "".concat(inspect(regexp), ". Input:\n\n").concat(inspect(string), "\n"));
  538. var err = new AssertionError({
  539. actual: string,
  540. expected: regexp,
  541. message: message,
  542. operator: fnName,
  543. stackStartFn: fn
  544. });
  545. err.generatedMessage = generatedMessage;
  546. throw err;
  547. }
  548. }
  549. assert.match = function match(string, regexp, message) {
  550. internalMatch(string, regexp, message, match, 'match');
  551. };
  552. assert.doesNotMatch = function doesNotMatch(string, regexp, message) {
  553. internalMatch(string, regexp, message, doesNotMatch, 'doesNotMatch');
  554. };
  555. // Expose a strict only variant of assert
  556. function strict() {
  557. for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  558. args[_key6] = arguments[_key6];
  559. }
  560. innerOk.apply(void 0, [strict, args.length].concat(args));
  561. }
  562. assert.strict = objectAssign(strict, assert, {
  563. equal: assert.strictEqual,
  564. deepEqual: assert.deepStrictEqual,
  565. notEqual: assert.notStrictEqual,
  566. notDeepEqual: assert.notDeepStrictEqual
  567. });
  568. assert.strict.strict = assert.strict;