use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapWhileCondition.
@Test
public void shouldWrapWhileCondition() throws Exception {
StringBuilder script = new StringBuilder("var x = 1;\n");
script.append("while (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(1.0));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldHandleTwoSeparateConditions.
@Test
public void shouldHandleTwoSeparateConditions() throws Exception {
StringBuilder script = new StringBuilder("function test(x) {\n");
script.append(" if (x < 0)\n");
script.append(" ;\n");
script.append(" else if (x > 100)\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[4][1]");
assertThat(coverageData1.callMember("covered"), equalTo(false));
assertThat(coverageData2.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", -1);
assertThat(coverageData1.callMember("covered"), equalTo(false));
assertThat(coverageData2.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", 1);
assertThat(coverageData1.callMember("covered"), equalTo(true));
assertThat(coverageData2.callMember("covered"), equalTo(false));
invocable.invokeFunction("test", 1000);
assertThat(coverageData1.callMember("covered"), equalTo(true));
assertThat(coverageData2.callMember("covered"), equalTo(true));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.
the class BranchInstrumentorIntegrationTest method shouldWrapWhileConditionVariable.
@Test
public void shouldWrapWhileConditionVariable() throws Exception {
StringBuilder script = new StringBuilder("var x = true;\n");
script.append("while (x)\n");
script.append(" x = false;\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(1.0));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.
the class EnginesController method installEngine.
private void installEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + engineDTO.getCategory() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("install", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
}, errorCallback), errorCallback);
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.
the class EnginesController method deleteEngine.
private void deleteEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + engineDTO.getCategory() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("delete", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
}, errorCallback), errorCallback);
}
Aggregations