/*
Test Helper Functions
968852
function compile(template) {
    el = $compile(template)(pageScope);
    root = $rootElement.append(el)[0];
    body = $document[0].body;
    body.appendChild(root);

    pageScope.$apply();

    return el;
  }
96271
function notfoundUnit (server) {
  var regexes = [];
  var callbacks = [];

  function notfound (paths, literalCall) {
    regexes.push(RegExp(paths));
    callbacks.push(literalCall);
  }

  server.notfound = notfound;

  return function notfoundLayer (req, res) {
    res.statusCode = 404;
    var matched = null;
    var cbindex = -1;
    for (var i = 0; i < regexes.length; i++) {
      matched = req.path.match (regexes[i]);
      if (matched !== null) { cbindex = i; break; }
    }
    if (cbindex >= 0) {
      catchpath(req, res, matched, callbacks[cbindex], server.templateReader);
    } else {
      res.end('Not Found\n');
    }
  };
}
655992
function (setUp, tearDown, fn) {
    return function (test) {
        var context = {};
        if (tearDown) {
            var done = test.done;
            test.done = function (err) {
                try {
                    tearDown.call(context, function (err2) {
                        if (err && err2) {
                            test._assertion_list.push(
                                types.assertion({error: err})
                            );
                            return done(err2);
                        }
                        done(err || err2);
                    });
                }
                catch (e) {
                    done(e);
                }
            };
        }
        if (setUp) {
            setUp.call(context, function (err) {
                if (err) {
                    return test.done(err);
                }
                fn.call(context, test);
            });
        }
        else {
            fn.call(context, test);
        }
    };
}
1326210
function(sControlName, aControlsToTest, aExcludedControls, bIncludeNonRenderable, bIncludeNonInstantiable) {
		if (!sControlName) {
			return false;
		}

		if (aControlsToTest.length) { // only test specific controls
			if (aControlsToTest.indexOf(sControlName) === -1) { // not one of the chosen ones
				return false;
			}
		} else if (aExcludedControls.indexOf(sControlName) > -1) {
			return false;
		}

		if (!bIncludeNonRenderable && !ControlIterator.controlCanBeRendered(sControlName)) {
			return false;
		}

		if (!bIncludeNonInstantiable && !ControlIterator.controlCanBeInstantiated(sControlName)) {
			return false;
		}

		return true;
	}
659286
function showHelp(specifiedScripts) {
    if (parsedArgv.help) {
      // if --help was specified, then yargs will show the default help
      log.info(help(psConfig))
      return true
    }
    const helpStyle = String(psConfig.options['help-style'])
    const hasDefaultScript = Boolean(psConfig.scripts.default)
    const noScriptSpecifiedAndNoDefault =
      !specifiedScripts.length && !hasDefaultScript
    const hasHelpScript = Boolean(psConfig.scripts.help)
    const commandIsHelp =
      isEqual(specifiedScripts[0], 'help') && !hasHelpScript
    const shouldShowSpecificScriptHelp =
      commandIsHelp && specifiedScripts.length > 1
    if (shouldShowSpecificScriptHelp) {
      log.info(specificHelpScript(psConfig, specifiedScripts[1]))
      return true
    } else if (commandIsHelp || noScriptSpecifiedAndNoDefault) {
      // Can't achieve 100% branch coverage without refactoring this showHelp()
      // function into ./index.js and re-working existing tests and such. Branch
      // options aren't relevant here either, so telling Istanbul to ignore.
      /* istanbul ignore next */
      if (helpStyle === 'all') {
        parser.showHelp('log')
      }
      log.info(help(psConfig))
      return true
    }

    return false
  }
503644
function (baseUrl, callback) {
    callback = callback || function (error, results) {
      if (error) {
        console.error.apply(console,
          error.stack ? [ error.stack ] : [ 'Error:', error ]);
      }
      var total = results.passed.length + results.failed.length;
      console.log('Results: ' + results.passed.length + '/' + total + ' test' +
        (total === 1 ? '' : 's') + ' passed.');
      if (results.failed.length > 0) {
        console.error('Failed:', jsonStringifyWithFunctions(results.failed));
      }
    };

    var results = {
      failed: [],
      passed: []
    };

    this.exportAllTests(baseUrl, function runNextTest (tests) {
      if (tests.length === 0) {
        callback(null, results);
        return;
      }

      var i = Math.floor(Math.random() * tests.length);
      var test = tests.splice(i, 1)[0];
      test(function (error, testResults) {
        if (testResults) {
          results.failed = results.failed.concat(testResults.failed);
          results.passed = results.passed.concat(testResults.passed);
        }
        if (error) {
          callback(error, results);
          return;
        }
        runNextTest(tests);
      });
    });
  }
784331
static function assertElementFound( $search, $element, $pageSection = null, $type = 'element' )
    {
        $section = ( $pageSection === null ) ? "" : " in '$pageSection' page section";
        Assertion::assertNotEmpty( $element, "Couldn't find '$search' $type" . $section );
    }
1057026
function each(test) {
        return function (Class) {
            var key,
                subject = context.subject,
                len;

            if (context.subjectConstructor === Array) {
                len = subject.length;
                for (key = 0; key < len; key++) {
                    value(subject[key]);
                    if (test(Class) === false) {
                        return false;
                    }
                }
            } else {
                for (key in subject) {
                    if (subject.hasOwnProperty(key)) {
                        value(subject[key]);
                        if (test(Class) === false) {
                            return false;
                        }
                    }
                }
            }
            return true;
        };
    }
792216
function stringMatch(stringValues) {
	return function(testValue) {
		for (var i = stringValues.length - 1; i >= 0; i--) {
			if (stringValues[i] === testValue) {
				return true;
			}
		}
		return false;
	};
}
188450
function(parent, name, type) {
			if (/^[0-9]+$/.test(name)) {
        return parent + "[" + name + "]";
      } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
	    	return parent + "." + name;
			}
			else {
				return parent + "['" + name + "']";
      }
    }
942346
function checkJs (mode, callback) {
  var exercise = this

  if (!exercise.passed)
    return callback(null, true) // shortcut if we've already had a failure

  gyp.rebuild(copyFauxTempDir, function (err) {
    if (err) {
      exercise.emit('fail', 'Compile mock C++ to test JavaScript: ' + err.message)
      return callback(null, false)
    }

    childProcess.exec(
          '"'
        + process.execPath
        + '" "'
        + copyFauxTempDir
        + '" "FAUX"'
      , function (err, stdout, stderr) {
          if (err) {
            process.stderr.write(stderr)
            process.stdout.write(stdout)
            return callback(err)
          }

          var pass = stdout.toString().replace('\r', '') == 'FAUX\n'
          if (!pass) {
            process.stderr.write(stderr)
            process.stdout.write(stdout)
          }
          exercise.emit(pass ? 'pass' : 'fail', 'JavaScript code loads addon and invokes `print(str)` method')

          callback(null, pass)
        }
    )
  })
}
599369
function assertMatch(actual, expected, message) {
  if (isRegExp(expected))
    assert(expected.test(actual), message || `Expected "${actual}" to match "${expected}"`);
  else if (typeof expected === 'function')
    assert(expected(actual), message);
  else
    assert.deepEqual(actual, expected, message);
}
482447
function(results, options) {
        console.log('')
        console.log('Passes: ' + results.stats.passes + ' Failures: ' + results.stats.failures)
        each(results.allSuites, function(suite) {
          if (suite.ran) {
            console.group(suite.description)
            each(suite.specs, function(spec){
              var assertionCount = spec.assertions.length + ':'
              if (spec.requiresImplementation())
                console.warn(spec.description)
              else if (spec.passed())
                console.log(assertionCount + ' ' + spec.description)
              else 
                console.error(assertionCount + ' ' + spec.description + ', ' + spec.failure().message)
            })
            console.groupEnd()
          }
        })
      }
820733
function checkFunction(node) {
            const scope = context.getScope();
            const regExpVar = astUtils.getVariableByName(scope, "RegExp");
            const shadowed = regExpVar && regExpVar.defs.length > 0;

            if (node.callee.type === "Identifier" && node.callee.name === "RegExp" && isString(node.arguments[0]) && !shadowed) {
                checkRegex(node, node.arguments[0].value, node.arguments[0].range[0] + 1);
            }
        }
1148869
function isGonnaBeLegen() {
        current = shift.call(queue);
        if (current) {
            if (typeof current == "function") {
                current = {name: current[NAME] || "anonymous", test: current};
            }
            log(OUTPUT_SEPARATOR);
            log(
                (iHasIt(current, NAME) && current[NAME])
                ||
                (iHasIt(current, DESCRIPTION) && current[DESCRIPTION])
                ||
                UNKNOWN
            );
            pass = [];
            fail = [];
            fatal = [];
            tmp = {};
            giveItATry("setup");
            fatal[LENGTH] || giveItATry("test");
            waitForIt || Dary();
        } else {
            showSummary();
        }
    }
119246
static function assertElementNotFound( $search, $element, $pageSection = null, $type = 'element' )
    {
        $section = ( $pageSection === null ) ? "" : " in '$pageSection' page section";
        Assertion::assertEmpty( $element, "Found '$search' $type" . $section );
    }
326536
function (test) {
        if (test.callback) {
            test.callback.fn.apply(test.callback.scope, test.callback.args);
        }
    }