Search in sources :

Example 21 with ScriptObjectMirror

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

Example 22 with ScriptObjectMirror

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

Example 23 with ScriptObjectMirror

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

Example 24 with ScriptObjectMirror

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

Example 25 with ScriptObjectMirror

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

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