forked from mozilla/rhino
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add *Test suffix to make tests actually run, remove stdout output, ad…
…d assertions.
- Loading branch information
Showing
5 changed files
with
120 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
35 changes: 16 additions & 19 deletions
35
.../org/mozilla/javascript/tests/conttest.js → ...org/mozilla/javascript/tests/Bug482203.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
var __terminate_interpreter__ = new Continuation(); | ||
java.lang.System.out.println("top"); | ||
var c; | ||
|
||
function fib(x) { | ||
c = getContinuation(); | ||
java.lang.System.out.println("fib(" + x + "); c = "+c); | ||
if(c != null) { | ||
java.lang.System.out.println("here"); | ||
this.__terminate_interpreter__(null); | ||
} | ||
return x < 2 ? 1 : (fib(x-1) + fib(x-2)); | ||
} | ||
|
||
function getContinuation() { | ||
return new Continuation(); | ||
} | ||
|
||
java.lang.System.out.println(fib(3)); | ||
var __terminate_interpreter__ = new Continuation(); | ||
var c; | ||
|
||
function fib(x) { | ||
c = getContinuation(); | ||
if(c != null) { | ||
this.__terminate_interpreter__(null); | ||
} | ||
return x < 2 ? 1 : (fib(x-1) + fib(x-2)); | ||
} | ||
|
||
function getContinuation() { | ||
return new Continuation(); | ||
} | ||
|
||
var result = fib(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.mozilla.javascript.tests; | ||
|
||
import java.io.InputStreamReader; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.mozilla.javascript.Callable; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.Script; | ||
import org.mozilla.javascript.Scriptable; | ||
import org.mozilla.javascript.ScriptableObject; | ||
|
||
public class Bug482203Test extends TestCase { | ||
|
||
public void testJsApi() throws Exception { | ||
Context cx = Context.enter(); | ||
try { | ||
cx.setOptimizationLevel(-1); | ||
Script script = cx.compileReader(new InputStreamReader( | ||
Bug482203Test.class.getResourceAsStream("Bug482203.js")), | ||
"", 1, null); | ||
Scriptable scope = cx.initStandardObjects(); | ||
script.exec(cx, scope); | ||
int counter = 0; | ||
for(;;) | ||
{ | ||
Object cont = ScriptableObject.getProperty(scope, "c"); | ||
if(cont == null) | ||
{ | ||
break; | ||
} | ||
counter++; | ||
((Callable)cont).call(cx, scope, scope, new Object[] { null }); | ||
} | ||
assertEquals(counter, 5); | ||
assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result")); | ||
} finally { | ||
Context.exit(); | ||
} | ||
} | ||
|
||
public void testJavaApi() throws Exception { | ||
Context cx = Context.enter(); | ||
try { | ||
cx.setOptimizationLevel(-1); | ||
Script script = cx.compileReader(new InputStreamReader( | ||
Bug482203Test.class.getResourceAsStream("Bug482203.js")), | ||
"", 1, null); | ||
Scriptable scope = cx.initStandardObjects(); | ||
cx.executeScriptWithContinuations(script, scope); | ||
int counter = 0; | ||
for(;;) | ||
{ | ||
Object cont = ScriptableObject.getProperty(scope, "c"); | ||
if(cont == null) | ||
{ | ||
break; | ||
} | ||
counter++; | ||
cx.resumeContinuation(cont, scope, null); | ||
} | ||
assertEquals(counter, 5); | ||
assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result")); | ||
} finally { | ||
Context.exit(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.mozilla.javascript.tests; | ||
|
||
import org.junit.Assert; | ||
import org.mozilla.javascript.Function; | ||
import org.mozilla.javascript.ContextFactory; | ||
import org.mozilla.javascript.ContextAction; | ||
import org.mozilla.javascript.Context; | ||
import org.junit.Test; | ||
|
||
public class Bug496585Test { | ||
public String method(String one, Function function) { | ||
return "string+function"; | ||
} | ||
|
||
public String method(String... strings) { | ||
return "string[]"; | ||
} | ||
|
||
@Test | ||
public void callOverloadedFunction() { | ||
new ContextFactory().call(new ContextAction() { | ||
public Object run(Context cx) { | ||
cx.getWrapFactory().setJavaPrimitiveWrap(false); | ||
Assert.assertEquals("string[]", cx.evaluateString( | ||
cx.initStandardObjects(), | ||
"new org.mozilla.javascript.tests.Bug496585Test().method('one', 'two', 'three')", | ||
"<test>", 1, null)); | ||
Assert.assertEquals("string+function", cx.evaluateString( | ||
cx.initStandardObjects(), | ||
"new org.mozilla.javascript.tests.Bug496585Test().method('one', function() {})", | ||
"<test>", 1, null)); | ||
return null; | ||
} | ||
}); | ||
} | ||
} |