Skip to content

Commit

Permalink
Add *Test suffix to make tests actually run, remove stdout output, ad…
Browse files Browse the repository at this point in the history
…d assertions.
  • Loading branch information
hns committed Dec 22, 2011
1 parent 5ce561e commit 31a8b73
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 107 deletions.
54 changes: 0 additions & 54 deletions testsrc/org/mozilla/javascript/tests/Bug482203.java

This file was deleted.

@@ -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);
68 changes: 68 additions & 0 deletions testsrc/org/mozilla/javascript/tests/Bug482203Test.java
@@ -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();
}
}
}
34 changes: 0 additions & 34 deletions testsrc/org/mozilla/javascript/tests/Bug496585.java

This file was deleted.

36 changes: 36 additions & 0 deletions testsrc/org/mozilla/javascript/tests/Bug496585Test.java
@@ -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;
}
});
}
}

0 comments on commit 31a8b73

Please sign in to comment.