Added test. Refactored test code: got rid of obsolete IncludeLibraryTest class.

This commit is contained in:
Pavel Talanov
2011-11-23 16:46:15 +04:00
parent cb7c05e550
commit e96c92358b
14 changed files with 105 additions and 30 deletions
@@ -3,7 +3,7 @@ package org.jetbrains.k2js.test;
/**
* @author Talanov Pavel
*/
public abstract class AbstractExpressionTest extends IncludeLibraryTest {
public abstract class AbstractExpressionTest extends TranslationTest {
private final String SUITE = "expression/";
@@ -5,7 +5,7 @@ import org.junit.Test;
/**
* @author Talanov Pavel
*/
public class BasicClassTest extends IncludeLibraryTest {
public class BasicClassTest extends TranslationTest {
final private static String MAIN = "class/";
@@ -5,7 +5,7 @@ import org.junit.Test;
/**
* @author Talanov Pavel
*/
public final class ClassInheritanceTest extends IncludeLibraryTest {
public final class ClassInheritanceTest extends TranslationTest {
final private static String MAIN = "inheritance/";
@@ -43,6 +43,11 @@ public final class ClassInheritanceTest extends IncludeLibraryTest {
public void baseClassDefinedAfterDerived() throws Exception {
testFooBoxIsTrue("baseClassDefinedAfterDerived.kt");
}
@Test
public void definitionOrder() throws Exception {
testFooBoxIsTrue("definitionOrder.kt");
}
}
@@ -1,16 +0,0 @@
package org.jetbrains.k2js.test;
import java.util.Arrays;
import java.util.List;
/**
* @author Talanov Pavel
*/
public abstract class IncludeLibraryTest extends TranslationTest {
@Override
protected List<String> generateFilenameList(String inputFile) {
return Arrays.asList(kotlinLibraryPath(), inputFile);
}
}
@@ -12,7 +12,7 @@ import java.util.Map;
/**
* @author Talanov Pavel
*/
public class KotlinLibTest extends IncludeLibraryTest {
public class KotlinLibTest extends TranslationTest {
final private static String MAIN = "kotlinLib/";
@@ -5,7 +5,7 @@ import org.junit.Test;
/**
* @author Talanov Pavel
*/
public class OperatorOverloadingTest extends IncludeLibraryTest {
public class OperatorOverloadingTest extends TranslationTest {
final private static String MAIN = "operatorOverloading/";
@@ -5,7 +5,7 @@ import org.junit.Test;
/**
* @author Talanov Pavel
*/
public final class PatternMatchingTest extends IncludeLibraryTest {
public final class PatternMatchingTest extends TranslationTest {
final private static String MAIN = "patternMatching/";
@@ -5,7 +5,7 @@ import org.junit.Test;
/**
* @author Talanov Pavel
*/
public final class PropertyAccessorTest extends IncludeLibraryTest {
public final class PropertyAccessorTest extends TranslationTest {
final private static String MAIN = "propertyAccess/";
@@ -5,7 +5,7 @@ import org.junit.Test;
/**
* @author Talanov Pavel
*/
public class RTTITest extends IncludeLibraryTest {
public class RTTITest extends TranslationTest {
final private static String MAIN = "rtti/";
@@ -5,7 +5,7 @@ import org.junit.Test;
/**
* @author Talanov Pavel
*/
public final class TraitTest extends IncludeLibraryTest {
public final class TraitTest extends TranslationTest {
final private static String MAIN = "trait/";
@@ -49,5 +49,10 @@ public final class TraitTest extends IncludeLibraryTest {
testFooBoxIsOk("funDelegation.jet");
}
@Test
public void definitionOrder() throws Exception {
testFooBoxIsTrue("definitionOrder.kt");
}
}
@@ -5,6 +5,7 @@ import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
@@ -16,7 +17,7 @@ public abstract class TranslationTest {
final protected static String TEST_FILES = "testFiles/";
final private static String CASES = "cases/";
final private static String OUT = "out/";
final private String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
final private static String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
protected abstract String mainDirectory();
@@ -62,7 +63,9 @@ public abstract class TranslationTest {
K2JSTranslator.translate(args);
}
abstract protected List<String> generateFilenameList(String inputfile);
protected List<String> generateFilenameList(String inputFile) {
return Arrays.asList(kotlinLibraryPath(), inputFile);
}
//TODO: refactor filename generation logic
private String getOutputFilePath(String filename) {
@@ -87,10 +90,10 @@ public abstract class TranslationTest {
reader.close();
}
protected void runRhinoTest(List<String> filenames, RhinoResultChecker checker) throws Exception {
protected void runRhinoTest(List<String> fileNames, RhinoResultChecker checker) throws Exception {
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
for (String filename : filenames) {
for (String filename : fileNames) {
runFileWithRhino(filename, cx, scope);
}
checker.runChecks(cx, scope);
@@ -3,7 +3,7 @@ package org.jetbrains.k2js.test;
/**
* @author Talanov Pavel
*/
public class TupleTest extends IncludeLibraryTest {
public class TupleTest extends TranslationTest {
final private static String MAIN = "tuple/";
@@ -0,0 +1,37 @@
namespace foo
class C() : B() {
{
order = order + "C"
}
}
class D() : B() {
{
order = order + "D"
}
}
class E() : A() {
{
order = order + "E"
}
}
open class B() : A() {
{
order = order + "B"
}
}
open class A() {
var order = ""
{
order = order + "A"
}
}
fun box() : Boolean {
return (C().order == "ABC") && (D().order == "ABD") && (E().order == "AE")
}
@@ -0,0 +1,41 @@
namespace foo
class C() : B() {
{
order = order + "C"
}
}
class D() : B() {
{
order = order + "D"
}
}
class E() : A() {
{
order = order + "E"
}
}
open class B() : A(), F {
{
order = order + "B"
}
}
open class A() : F {
var order = ""
{
order = order + "A"
}
}
trait F {
fun bar() = "F"
}
fun box() : Boolean {
return (C().order == "ABC") && (D().order == "ABD") && (E().order == "AE") && (C().bar() == "F") && (A().bar() == "F")
}