From ba3dacbe5aca4a76055cd4f0617b05627024c6c3 Mon Sep 17 00:00:00 2001
From: jugglinmike <mike@mikepennisi.com>
Date: Thu, 21 Apr 2016 15:55:54 -0400
Subject: [PATCH] Correct tests for native functions' toString value (#580)

Modify the regular expression for native functions' toString value to
satisfy all test cases. Correct the test file's reference to the harness
file. Re-format the test file's assertions to aid debugging in the event
of failure.
---
 harness/nativeFunctionMatcher.js      |  6 ++-
 test/harness/nativeFunctionMatcher.js | 58 +++++++++++++++++++--------
 2 files changed, 47 insertions(+), 17 deletions(-)

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 }"');
+}
-- 
GitLab