Search in sources :

Example 16 with ScriptObjectMirror

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));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 17 with ScriptObjectMirror

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));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 18 with ScriptObjectMirror

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));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 19 with ScriptObjectMirror

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));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 20 with ScriptObjectMirror

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));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror)

Aggregations

ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)76 Test (org.junit.Test)34 InteractiveScriptSession (org.phoenicis.scripts.interpreter.InteractiveScriptSession)28 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)28 Consumer (java.util.function.Consumer)27 List (java.util.List)23 LoggerFactory (org.slf4j.LoggerFactory)20 File (java.io.File)17 IOException (java.io.IOException)17 Logger (org.slf4j.Logger)14 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 RegistryParameter (org.phoenicis.containers.wine.parameters.RegistryParameter)10 LibraryManager (org.phoenicis.library.LibraryManager)10 ShortcutManager (org.phoenicis.library.ShortcutManager)10 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)10 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)10 RegistryWriter (org.phoenicis.win32.registry.RegistryWriter)10 URI (java.net.URI)8