diff --git a/harness/nativeFunctionMatcher.js b/harness/nativeFunctionMatcher.js index 812c9a9041..f902f34141 100644 --- a/harness/nativeFunctionMatcher.js +++ b/harness/nativeFunctionMatcher.js @@ -1 +1,5 @@ -const NATIVE_FUNCTION_RE = /\bfunction\b[\s\S]+\b\w+\b[\s\S]*\([\s\S]*\)[\s\S]*\{[\s\S]*\[[\s\S]*\bnative\b[\s\S]+\bcode\b[\s\S]*\][\s\S]*\}/; +/** + * This regex makes a best-effort determination that the tested string matches + * the NativeFunction grammar production without requiring a correct tokeniser. + */ +const NATIVE_FUNCTION_RE = /\bfunction\b[\s\S]*\([\s\S]*\)[\s\S]*\{[\s\S]*\[[\s\S]*\bnative\b[\s\S]+\bcode\b[\s\S]*\][\s\S]*\}/; diff --git a/test/harness/nativeFunctionMatcher.js b/test/harness/nativeFunctionMatcher.js index 6bd51fc357..bfe45b6f63 100644 --- a/test/harness/nativeFunctionMatcher.js +++ b/test/harness/nativeFunctionMatcher.js @@ -3,21 +3,47 @@ /*--- description: > - Provides a regex that makes a best-effort determination that the tested - string matches the NativeFunction grammar production without requiring a - correct tokeniser -includes: [nativeFunctionHelper.js] + Ensure that the regular expression generally distinguishes between valid + and invalid forms of the NativeFunction grammar production. +includes: [nativeFunctionMatcher.js] ---*/ -if (!( - NATIVE_FUNCTION_RE.test('function(){[native function]}') && - NATIVE_FUNCTION_RE.test('function(){ [native function] }') && - NATIVE_FUNCTION_RE.test('function ( ) { [ native function ] }') && - NATIVE_FUNCTION_RE.test('function a(){ [native function] }') && - NATIVE_FUNCTION_RE.test('function a(){ /* } */ [native function] }') && - !NATIVE_FUNCTION_RE.test('') && - !NATIVE_FUNCTION_RE.test('native function') && - !NATIVE_FUNCTION_RE.test('function(){}') && - !NATIVE_FUNCTION_RE.test('function(){ "native function" }') && - !NATIVE_FUNCTION_RE.test('function(){ [] native function }') -)) $ERROR('NATIVE_FUNCTION_RE failed'); +if (!NATIVE_FUNCTION_RE.test('function(){[native code]}')) { + $ERROR('expected string to pass: "function(){[native code]}"'); +} + +if (!NATIVE_FUNCTION_RE.test('function(){ [native code] }')) { + $ERROR('expected string to pass: "function(){ [native code] }"'); +} + +if (!NATIVE_FUNCTION_RE.test('function ( ) { [ native code ] }')) { + $ERROR('expected string to pass: "function ( ) { [ native code ] }"'); +} + +if (!NATIVE_FUNCTION_RE.test('function a(){ [native code] }')) { + $ERROR('expected string to pass: "function a(){ [native code] }"'); +} + +if (!NATIVE_FUNCTION_RE.test('function a(){ /* } */ [native code] }')) { + $ERROR('expected string to pass: "function a(){ /* } */ [native code] }"'); +} + +if (NATIVE_FUNCTION_RE.test('')) { + $ERROR('expected string to fail: ""'); +} + +if (NATIVE_FUNCTION_RE.test('native code')) { + $ERROR('expected string to fail: "native code"'); +} + +if (NATIVE_FUNCTION_RE.test('function(){}')) { + $ERROR('expected string to fail: "function(){}"'); +} + +if (NATIVE_FUNCTION_RE.test('function(){ "native code" }')) { + $ERROR('expected string to fail: "function(){ "native code" }"'); +} + +if (NATIVE_FUNCTION_RE.test('function(){ [] native code }')) { + $ERROR('expected string to fail: "function(){ [] native code }"'); +}