use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldHandleVariableAsIfConditions.
@Test
public void shouldHandleVariableAsIfConditions() throws Exception {
StringBuilder script = new StringBuilder("function test(x) {\n");
script.append(" if (x)\n");
script.append(" ;\n");
script.append("};\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(0));
assertThat(coverageData.get("position"), equalTo(6));
assertThat(coverageData.get("nodeLength"), equalTo(1));
assertThat(coverageData.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", true);
assertThat(coverageData.get("evalTrue"), equalTo(1.0));
assertThat(coverageData.get("evalFalse"), equalTo(0));
assertThat(coverageData.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", false);
assertThat(coverageData.get("evalTrue"), equalTo(1.0));
assertThat(coverageData.get("evalFalse"), equalTo(1.0));
assertThat(coverageData.callMember("covered"), equalTo(true));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapTernaryConditionParentheses.
@Test
public void shouldWrapTernaryConditionParentheses() throws Exception {
StringBuilder script = new StringBuilder("var y = true;\n");
script.append("var x = (y) ? 1 : 2;\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 shouldWrapExpressionCondition.
@Test
public void shouldWrapExpressionCondition() throws Exception {
StringBuilder script = new StringBuilder("function test(x) {;\n");
script.append(" x || (x = 0);\n");
script.append("}\n");
script.append("test();\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 shouldWrapIfCondition.
@Test
public void shouldWrapIfCondition() throws Exception {
StringBuilder script = new StringBuilder("var x = 1;\n");
script.append("if (x > 0)\n");
script.append(" x--;\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 testNestedScript.
private void testNestedScript(StringBuilder script) throws Exception {
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(true));
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