MCPcopy Index your code
hub / github.com/jquery/esprima / testError

Function testError

test/utils/evaluate-testcase.js:312–374  ·  view source on GitHub ↗
(testCase)

Source from the content-addressed store, hash-verified

310 }
311
312 function testError(testCase) {
313 'use strict';
314 var sourceType, i, options, exception, expected, code, actual, err, handleInvalidRegexFlag, tokenize;
315
316 // Different parsing options should give the same error.
317 sourceType = testCase.key.match(/\.module$/) ? 'module' : 'script';
318 options = [
319 { jsx: true, sourceType: sourceType },
320 { jsx: true, comment: true, sourceType: sourceType },
321 { jsx: true, raw: true, sourceType: sourceType },
322 { jsx: true, raw: true, comment: true, sourceType: sourceType }
323 ];
324
325 // If handleInvalidRegexFlag is true, an invalid flag in a regular expression
326 // will throw an exception. In some old version of V8, this is not the case
327 // and hence handleInvalidRegexFlag is false.
328 handleInvalidRegexFlag = false;
329 try {
330 'test'.match(new RegExp('[a-z]', 'x'));
331 } catch (e) {
332 handleInvalidRegexFlag = true;
333 }
334
335 exception = testCase.failure;
336 exception.description = exception.message.replace(/Error: Line [0-9]+: /, '');
337
338 if (exception.tokenize) {
339 tokenize = true;
340 exception.tokenize = undefined;
341 }
342
343 expected = JSON.stringify(exception);
344
345 code = testCase.case || testCase.source || '';
346
347 for (i = 0; i < options.length; i += 1) {
348
349 try {
350 if (tokenize) {
351 esprima.tokenize(code, options[i]);
352 } else {
353 esprima.parse(code, options[i]);
354 }
355 } catch (e) {
356 err = errorToObject(e);
357 err.description = e.description;
358 actual = JSON.stringify(err);
359 }
360
361 if (expected !== actual) {
362
363 // Compensate for old V8 which does not handle invalid flag.
364 if (exception.message.indexOf('Invalid regular expression') > 0) {
365 if (typeof actual === 'undefined' && !handleInvalidRegexFlag) {
366 return;
367 }
368 }
369

Callers 1

Calls 1

matchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…