use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapDoConditionVariable.
@Test
public void shouldWrapDoConditionVariable() throws Exception {
StringBuilder script = new StringBuilder("var x = true;\n");
script.append("do\n");
script.append(" x = false;\n");
script.append("while (x)\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[4][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 shouldWrapForCondition.
@Test
public void shouldWrapForCondition() throws Exception {
StringBuilder script = new StringBuilder("for (var i = 0; i < 1; i++)\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(1.0));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapTernaryConditionWithParentheses.
@Test
public void shouldWrapTernaryConditionWithParentheses() throws Exception {
StringBuilder script = new StringBuilder("var x = 10;\n");
script.append("var y = (x > 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 shouldWrapTernaryConditionVariable.
@Test
public void shouldWrapTernaryConditionVariable() 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 shouldWrapFunctionCallConditionAsFirstArgument.
@Test
public void shouldWrapFunctionCallConditionAsFirstArgument() throws Exception {
StringBuilder script = new StringBuilder("function test(x, y) {};\n");
script.append("test(1 > 0, 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));
}
Aggregations