use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapAssignmentCondition.
@Test
public void shouldWrapAssignmentCondition() throws Exception {
StringBuilder script = new StringBuilder("var x = true;\n");
script.append("x = x === undefined;\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
assertThat(coverageData.get("evalTrue"), equalTo(0));
assertThat(coverageData.get("evalFalse"), equalTo(1.0));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapIfConditionVariable.
@Test
public void shouldWrapIfConditionVariable() throws Exception {
StringBuilder script = new StringBuilder("var x = true;\n");
script.append("if (x)\n");
script.append(" x = false;\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
assertThat(coverageData.get("evalTrue"), equalTo(1.0));
assertThat(coverageData.get("evalFalse"), equalTo(0));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapNot.
@Test
public void shouldWrapNot() throws Exception {
StringBuilder script = new StringBuilder("function test(x) {\n");
script.append(" if (!(x < 0))\n");
script.append(" ;\n");
script.append("};\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData1 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
ScriptObjectMirror coverageData2 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][2]");
assertThat(coverageData1.callMember("covered"), equalTo(false));
assertThat(coverageData2.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", -1);
assertThat(coverageData1.callMember("covered"), equalTo(false));
assertThat(coverageData2.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", 1);
assertThat(coverageData1.callMember("covered"), equalTo(true));
assertThat(coverageData2.callMember("covered"), equalTo(true));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapCoalesce.
@Test
public void shouldWrapCoalesce() throws Exception {
StringBuilder script = new StringBuilder("function test(a) {\n var x = a || {};\n }\ntest();");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
assertThat(coverageData.get("evalTrue"), equalTo(1.0));
assertThat(coverageData.get("evalFalse"), equalTo(0));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldHandleFunctionAsIfConditions.
@Test
public void shouldHandleFunctionAsIfConditions() throws Exception {
StringBuilder script = new StringBuilder("function fn() { return true;}\n");
script.append(" if (fn())\n");
script.append(" ;\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
assertThat(coverageData.get("evalTrue"), equalTo(1.0));
assertThat(coverageData.get("evalFalse"), equalTo(0));
}
Aggregations