use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldHandleSingleCondition.
@Test
public void shouldHandleSingleCondition() 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 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(5));
assertThat(coverageData.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", -1);
assertThat(coverageData.get("evalTrue"), equalTo(1.0));
assertThat(coverageData.get("evalFalse"), equalTo(0));
assertThat(coverageData.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", 1);
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 shouldWrapNotOperatorCondition.
@Test
public void shouldWrapNotOperatorCondition() throws Exception {
StringBuilder script = new StringBuilder("function test(x) {\n");
script.append(" if (!x)\n");
script.append(" ;\n");
script.append("};\n");
script.append("test(true);\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 shouldWrapDoCondition.
@Test
public void shouldWrapDoCondition() throws Exception {
StringBuilder script = new StringBuilder("var x = 1;\n");
script.append("do\n");
script.append(" x--;\n");
script.append("while (x > 0)\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 shouldWrapGetterCondition.
@Test
public void shouldWrapGetterCondition() throws Exception {
StringBuilder script = new StringBuilder("var y = { 'a':1, 'b':2};\n");
script.append("var prop = null;\n");
script.append("var x = y[prop || 'a'];");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[3][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 shouldWrapReturnCondition.
@Test
public void shouldWrapReturnCondition() throws Exception {
StringBuilder script = new StringBuilder("function test(x) {\n");
script.append(" return x > 0\n");
script.append("}\n");
script.append("test(1);");
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