Search in sources :

Example 51 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldNotBreakCommaCondition2.

@Test
public void shouldNotBreakCommaCondition2() throws Exception {
    StringBuilder script = new StringBuilder("if (false, true)\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(0));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 52 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldWrapFunctionCallCondition.

@Test
public void shouldWrapFunctionCallCondition() throws Exception {
    StringBuilder script = new StringBuilder("function test(x, y) {};\n");
    script.append("test(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));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 53 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldWrapTernaryConditionArgument.

@Test
public void shouldWrapTernaryConditionArgument() throws Exception {
    StringBuilder script = new StringBuilder("var x = 10;\n");
    script.append("var y = x > 0 ? x >= 100 : x < 100;\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));
    ScriptObjectMirror coverageData2 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][2]");
    assertThat(coverageData2.get("evalTrue"), equalTo(0));
    assertThat(coverageData2.get("evalFalse"), equalTo(1.0));
    ScriptObjectMirror coverageData3 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][3]");
    assertThat(coverageData3.get("evalTrue"), equalTo(0));
    assertThat(coverageData3.get("evalFalse"), equalTo(0));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 54 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldWrapSwitchCondition.

@Test
public void shouldWrapSwitchCondition() throws Exception {
    StringBuilder script = new StringBuilder("  switch (null || 'd') {\n");
    script.append("    case 'd' : case 'D' :\n");
    script.append("      break;\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(0));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 55 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldWrapOr.

@Test
public void shouldWrapOr() throws Exception {
    StringBuilder script = new StringBuilder("function test(x, y) {\n");
    script.append("  if ((x < 0) || (y <= 0))\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[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(false));
    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) Test(org.junit.Test)

Aggregations

ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)73 Test (org.junit.Test)34 InteractiveScriptSession (org.phoenicis.scripts.interpreter.InteractiveScriptSession)24 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)24 Consumer (java.util.function.Consumer)23 List (java.util.List)20 LoggerFactory (org.slf4j.LoggerFactory)19 File (java.io.File)16 IOException (java.io.IOException)16 Logger (org.slf4j.Logger)13 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)12 Map (java.util.Map)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 RegistryWriter (org.phoenicis.win32.registry.RegistryWriter)10 ArrayList (java.util.ArrayList)9 Platform (javafx.application.Platform)8 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)8