Split expression tests into different categories.

This commit is contained in:
Pavel Talanov
2011-11-18 13:12:47 +04:00
parent 95ab245f15
commit 37ea3c75ca
29 changed files with 245 additions and 149 deletions
@@ -400,8 +400,23 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
@NotNull
public JsNode visitBinaryWithTypeRHSExpression(@NotNull JetBinaryExpressionWithTypeRHS expression,
@NotNull TranslationContext context) {
// we actually do not care for types in js
return Translation.translateExpression(expression.getLeft(), context);
}
@Override
@NotNull
public JsNode visitBreakExpression(@NotNull JetBreakExpression expression,
@NotNull TranslationContext context) {
return new JsBreak();
}
@Override
@NotNull
public JsNode visitContinueExpression(@NotNull JetContinueExpression expression,
@NotNull TranslationContext context) {
return new JsContinue();
}
}
@@ -0,0 +1,22 @@
package org.jetbrains.k2js.test;
import java.util.Arrays;
import java.util.List;
/**
* @author Talanov Pavel
*/
public abstract class AbstractExpressionTest extends TranslationTest {
private final String SUITE = "expression/";
@Override
protected List<String> generateFilenameList(String inputFile) {
return Arrays.asList(inputFile);
}
@Override
protected String suiteDirectoryName() {
return SUITE;
}
}
@@ -0,0 +1,31 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Talanov Pavel
*/
public class ConditionalTest extends AbstractExpressionTest {
final private static String MAIN = "conditional/";
@Override
protected String mainDirectory() {
return MAIN;
}
@Test
public void ifElseAsExpression() throws Exception {
testFooBoxIsTrue("ifElseAsExpression.kt");
}
@Test
public void ifElse() throws Exception {
testFunctionOutput("if.kt", "foo", "box", 5);
}
//TODO: test fails due to isStatement issue, include when issue is solved or implement another solution
// @Test
// public void ifElseIf() throws Exception {
// testFunctionOutput("elseif.kt", "foo", "box", 5);
// }
}
@@ -1,122 +0,0 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
/**
* @author Talanov Pavel
* <p/>
* This class tests basic language features and constructs such as constants, local variables, simple loops,
* conditional clauses etc.
*/
public final class ExpressionTest extends TranslationTest {
private static final String MAIN = "expression/";
protected String mainDirectory() {
return MAIN;
}
@Override
protected List<String> generateFilenameList(String inputFile) {
return Arrays.asList(inputFile);
}
@Test
public void currentTest() throws Exception {
testFooBoxIsTrue("test.kt");
}
@Test
public void testAssign() throws Exception {
testFunctionOutput("assign.jet", "foo", "f", 2.0);
}
@Test
public void namespaceProperties() throws Exception {
testFunctionOutput("localProperty.jet", "foo", "box", 50);
}
@Test
public void comparison() throws Exception {
testFooBoxIsTrue("comparison.kt");
}
@Test
public void ifElse() throws Exception {
testFunctionOutput("if.kt", "foo", "box", 5);
}
//TODO: test fails due to isStatement issue, include when issue is solved or implement another solution
// @Test
// public void ifElseIf() throws Exception {
// testFunctionOutput("elseif.kt", "foo", "box", 5);
// }
@Test
public void whileSimpleTest() throws Exception {
testFooBoxIsTrue("while.kt");
}
@Test
public void doWhileSimpleTest() throws Exception {
testFooBoxIsTrue("doWhile.kt");
}
@Test
public void doWhileExecutesAtLeastOnce() throws Exception {
testFooBoxIsTrue("doWhile2.kt");
}
@Test
public void whileDoesntExecuteEvenOnceIfConditionIsFalse() throws Exception {
testFooBoxIsTrue("while2.kt");
}
@Test
public void stringConstant() throws Exception {
testFooBoxIsTrue("stringConstant.kt");
}
@Test
public void stringAssignment() throws Exception {
testFooBoxIsTrue("stringAssignment.kt");
}
@Test
public void functionUsedBeforeDeclaration() throws Exception {
testFooBoxIsTrue("functionUsedBeforeDeclaration.kt");
}
@Test
public void functionWithTwoParametersCall() throws Exception {
testFooBoxIsTrue("functionWithTwoParametersCall.kt");
}
@Test
public void prefixIntOperations() throws Exception {
testFooBoxIsTrue("prefixIntOperations.kt");
}
@Test
public void postfixIntOperations() throws Exception {
testFooBoxIsTrue("postfixIntOperations.kt");
}
@Test
public void notBoolean() throws Exception {
testFooBoxIsTrue("notBoolean.kt");
}
@Test
public void positiveAndNegativeNumbers() throws Exception {
testFooBoxIsTrue("positiveAndNegativeNumbers.kt");
}
@Test
public void ifElseAsExpression() throws Exception {
testFooBoxIsTrue("ifElseAsExpression.kt");
}
}
@@ -0,0 +1,26 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Talanov Pavel
*/
public class FunctionTest extends AbstractExpressionTest {
final private static String MAIN = "function/";
@Override
protected String mainDirectory() {
return MAIN;
}
@Test
public void functionUsedBeforeDeclaration() throws Exception {
testFooBoxIsTrue("functionUsedBeforeDeclaration.kt");
}
@Test
public void functionWithTwoParametersCall() throws Exception {
testFooBoxIsTrue("functionWithTwoParametersCall.kt");
}
}
@@ -0,0 +1,23 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Talanov Pavel
* <p/>
* This class contains tests that do not fall in any particular category
* most probably because that functionality has very little support
*/
public class MiscTest extends AbstractExpressionTest {
final private static String MAIN = "misc/";
@Override
protected String mainDirectory() {
return MAIN;
}
@Test
public void namespaceProperties() throws Exception {
testFunctionOutput("localProperty.jet", "foo", "box", 50);
}
}
@@ -0,0 +1,45 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Talanov Pavel
*/
public class OperationTest extends AbstractExpressionTest {
final private static String MAIN = "operation/";
@Override
protected String mainDirectory() {
return MAIN;
}
@Test
public void prefixIntOperations() throws Exception {
testFooBoxIsTrue("prefixIntOperations.kt");
}
@Test
public void postfixIntOperations() throws Exception {
testFooBoxIsTrue("postfixIntOperations.kt");
}
@Test
public void notBoolean() throws Exception {
testFooBoxIsTrue("notBoolean.kt");
}
@Test
public void positiveAndNegativeNumbers() throws Exception {
testFooBoxIsTrue("positiveAndNegativeNumbers.kt");
}
@Test
public void assign() throws Exception {
testFunctionOutput("assign.jet", "foo", "f", 2.0);
}
@Test
public void comparison() throws Exception {
testFooBoxIsTrue("comparison.kt");
}
}
@@ -0,0 +1,26 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Talanov Pavel
*/
public class StringTest extends AbstractExpressionTest {
final private static String MAIN = "string/";
@Override
protected String mainDirectory() {
return MAIN;
}
@Test
public void stringConstant() throws Exception {
testFooBoxIsTrue("stringConstant.kt");
}
@Test
public void stringAssignment() throws Exception {
testFooBoxIsTrue("stringAssignment.kt");
}
}
@@ -1,7 +1,6 @@
package org.jetbrains.k2js.test;
import org.jetbrains.k2js.K2JSTranslator;
import org.junit.Before;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
@@ -19,29 +18,34 @@ public abstract class TranslationTest {
final private static String OUT = "out/";
final private String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
protected String testFilesDirectory;
protected String testCasesDirectory;
protected String outputDirectory;
@Before
public void setUpClass() {
testCasesDirectory = CASES;
outputDirectory = OUT;
testFilesDirectory = TEST_FILES + mainDirectory();
}
protected abstract String mainDirectory();
protected String kotlinLibraryPath() {
return KOTLIN_JS_LIB;
}
private String getOutputDirectory() {
return testFilesDirectory + outputDirectory;
private String casesDirectoryName() {
return CASES;
}
private String getInputDirectory() {
return testFilesDirectory + testCasesDirectory;
private String outDirectoryName() {
return OUT;
}
private String testFilesPath() {
return TEST_FILES + suiteDirectoryName() + mainDirectory();
}
protected String suiteDirectoryName() {
return "";
}
private String getOutputPath() {
return testFilesPath() + outDirectoryName();
}
private String getInputPath() {
return testFilesPath() + casesDirectoryName();
}
protected void testFunctionOutput(String filename, String namespaceName,
@@ -62,7 +66,7 @@ public abstract class TranslationTest {
//TODO: refactor filename generation logic
private String getOutputFilePath(String filename) {
return getOutputDirectory() + convertToDotJsFile(filename);
return getOutputPath() + convertToDotJsFile(filename);
}
private String convertToDotJsFile(String filename) {
@@ -70,7 +74,7 @@ public abstract class TranslationTest {
}
private String getInputFilePath(String filename) {
return getInputDirectory() + filename;
return getInputPath() + filename;
}
protected String cases(String filename) {
@@ -0,0 +1,35 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Talanov Pavel
*/
public final class WhileTest extends AbstractExpressionTest {
private static final String MAIN = "while/";
protected String mainDirectory() {
return MAIN;
}
@Test
public void whileSimpleTest() throws Exception {
testFooBoxIsTrue("while.kt");
}
@Test
public void doWhileSimpleTest() throws Exception {
testFooBoxIsTrue("doWhile.kt");
}
@Test
public void doWhileExecutesAtLeastOnce() throws Exception {
testFooBoxIsTrue("doWhile2.kt");
}
@Test
public void whileDoesntExecuteEvenOnceIfConditionIsFalse() throws Exception {
testFooBoxIsTrue("while2.kt");
}
}
@@ -1,9 +0,0 @@
namespace foo
fun box() : Boolean {
val a = 2;
val b = 3;
var c = 4;
return (a < c)
}