use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldNotBreakCommaCondition.
@Test
public void shouldNotBreakCommaCondition() throws Exception {
StringBuilder script = new StringBuilder("if (true, false)\n");
script.append(" ;\n");
runScript(script.toString(), false);
ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[1][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 shouldWrapTernaryCondition.
@Test
public void shouldWrapTernaryCondition() 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 shouldWrapArrayLiteralCondition.
@Test
public void shouldWrapArrayLiteralCondition() throws Exception {
StringBuilder script = new StringBuilder("var x = [ 1 || 0];\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 shouldWrapStringKeyCondition.
@Test
public void shouldWrapStringKeyCondition() throws Exception {
StringBuilder script = new StringBuilder("var x = 0; var a = {\n");
script.append(" key: x || 1\n");
script.append("};\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));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldHandleVariableInitializer.
@Test
public void shouldHandleVariableInitializer() throws Exception {
StringBuilder script = new StringBuilder("function test(x) {\n");
script.append(" var y = x < 0;\n");
script.append(" return y;\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(10));
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));
}
Aggregations