use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldNotBreakCommaCondition2.
@Test
public void shouldNotBreakCommaCondition2() throws Exception {
StringBuilder script = new StringBuilder("if (false, true)\n");
script.append(" ;\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[1][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 shouldWrapFunctionCallCondition.
@Test
public void shouldWrapFunctionCallCondition() throws Exception {
StringBuilder script = new StringBuilder("function test(x, y) {};\n");
script.append("test(0, 1 > 0);\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 shouldWrapTernaryConditionArgument.
@Test
public void shouldWrapTernaryConditionArgument() throws Exception {
StringBuilder script = new StringBuilder("var x = 10;\n");
script.append("var y = x > 0 ? x >= 100 : x < 100;\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData1 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
assertThat(coverageData1.get("evalTrue"), equalTo(1.0));
assertThat(coverageData1.get("evalFalse"), equalTo(0));
ScriptObjectMirror coverageData2 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][2]");
assertThat(coverageData2.get("evalTrue"), equalTo(0));
assertThat(coverageData2.get("evalFalse"), equalTo(1.0));
ScriptObjectMirror coverageData3 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][3]");
assertThat(coverageData3.get("evalTrue"), equalTo(0));
assertThat(coverageData3.get("evalFalse"), equalTo(0));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapSwitchCondition.
@Test
public void shouldWrapSwitchCondition() throws Exception {
StringBuilder script = new StringBuilder(" switch (null || 'd') {\n");
script.append(" case 'd' : case 'D' :\n");
script.append(" break;\n");
script.append("}\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[1][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 shouldWrapOr.
@Test
public void shouldWrapOr() throws Exception {
StringBuilder script = new StringBuilder("function test(x, y) {\n");
script.append(" if ((x < 0) || (y <= 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]");
ScriptObjectMirror coverageData3 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][3]");
assertThat(coverageData1.callMember("covered"), equalTo(false));
assertThat(coverageData2.callMember("covered"), equalTo(false));
assertThat(coverageData3.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", -1, -1);
assertThat(coverageData1.callMember("covered"), equalTo(false));
assertThat(coverageData2.callMember("covered"), equalTo(false));
assertThat(coverageData3.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", 1, -1);
assertThat(coverageData1.callMember("covered"), equalTo(false));
assertThat(coverageData2.callMember("covered"), equalTo(true));
assertThat(coverageData3.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", 1, 1);
assertThat(coverageData1.callMember("covered"), equalTo(true));
assertThat(coverageData2.callMember("covered"), equalTo(true));
assertThat(coverageData3.callMember("covered"), equalTo(true));
}
Aggregations