before merge
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="js.backend" />
|
||||
<orderEntry type="library" name="idea-full" level="application" />
|
||||
<orderEntry type="library" name="js" level="application" />
|
||||
<orderEntry type="library" name="guava-10.0.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class AbstractExpressionTest extends TranslationTest {
|
||||
|
||||
private final String SUITE = "expression/";
|
||||
|
||||
@Override
|
||||
protected String suiteDirectoryName() {
|
||||
return SUITE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.mozilla.javascript.JavaScriptException;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ArrayListTest extends JavaClassesTest {
|
||||
|
||||
final private static String MAIN = "arrayList/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testEmptyList() throws Exception {
|
||||
testFooBoxIsTrue("emptyList.kt");
|
||||
}
|
||||
|
||||
public void testAccess() throws Exception {
|
||||
testFooBoxIsTrue("access.kt");
|
||||
}
|
||||
|
||||
public void testIsEmpty() throws Exception {
|
||||
testFooBoxIsTrue("isEmpty.kt");
|
||||
}
|
||||
|
||||
public void testArrayAccess() throws Exception {
|
||||
testFooBoxIsTrue("arrayAccess.kt");
|
||||
}
|
||||
|
||||
public void testIterate() throws Exception {
|
||||
testFooBoxIsTrue("iterate.kt");
|
||||
}
|
||||
|
||||
public void testRemove() throws Exception {
|
||||
testFooBoxIsTrue("remove.kt");
|
||||
}
|
||||
|
||||
public void testIndexOOB() throws Exception {
|
||||
try {
|
||||
testFooBoxIsTrue("indexOOB.kt");
|
||||
fail();
|
||||
} catch (JavaScriptException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.compiler.JetCoreEnvironment;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class BaseTest extends UsefulTestCase {
|
||||
@NonNls
|
||||
protected JetCoreEnvironment myEnvironment;
|
||||
|
||||
public Project getProject() {
|
||||
return myEnvironment.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// createEnvironmentWithMockJdk();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myEnvironment = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void createEnvironmentWithMockJdk() {
|
||||
myEnvironment = JetTestUtils.createEnvironmentWithMockJdk(getTestRootDisposable());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
//TODO: remove class
|
||||
public class BasicClassTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "class/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testClassWithoutNamespace() throws Exception {
|
||||
testFunctionOutput("classWithoutNamespace.kt", "Anonymous", "box", true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ClassInheritanceTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "inheritance/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testInitializersOfBasicClassExecute() throws Exception {
|
||||
testFunctionOutput("initializersOfBasicClassExecute.kt", "foo", "box", 3);
|
||||
}
|
||||
|
||||
public void testMethodOverride() throws Exception {
|
||||
testFooBoxIsTrue("methodOverride.kt");
|
||||
}
|
||||
|
||||
public void testInitializationOrder() throws Exception {
|
||||
testFooBoxIsTrue("initializationOrder.kt");
|
||||
}
|
||||
|
||||
public void testComplexInitializationOrder() throws Exception {
|
||||
testFooBoxIsTrue("complexInitializationOrder.kt");
|
||||
}
|
||||
|
||||
public void testValuePassedToAncestorConstructor() throws Exception {
|
||||
testFooBoxIsTrue("valuePassedToAncestorConstructor.kt");
|
||||
}
|
||||
|
||||
public void testBaseClassDefinedAfterDerived() throws Exception {
|
||||
testFooBoxIsTrue("baseClassDefinedAfterDerived.kt");
|
||||
}
|
||||
|
||||
public void testDefinitionOrder() throws Exception {
|
||||
testFooBoxIsTrue("definitionOrder.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.mozilla.javascript.JavaScriptException;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
//TODO: remove class
|
||||
public class ConditionalTest extends AbstractExpressionTest {
|
||||
|
||||
final private static String MAIN = "conditional/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testIfElseAsExpressionWithThrow() throws Exception {
|
||||
try {
|
||||
testFooBoxIsTrue("ifAsExpressionWithThrow.kt");
|
||||
fail();
|
||||
} catch (JavaScriptException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ExampleTestSuite extends UsefulTestCase {
|
||||
|
||||
public static Test suite() {
|
||||
return Suite.suiteForDirectory("examples/", new Suite.SingleFileTester() {
|
||||
@Override
|
||||
public void performTest(@NotNull Suite test, @NotNull String filename) throws Exception {
|
||||
test.testFunctionOutput(filename, "Anonymous", "box", "OK");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ExtensionFunctionTest extends TranslationTest {
|
||||
final private static String MAIN = "extensionFunction/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testIntExtension() throws Exception {
|
||||
testFooBoxIsTrue("intExtension.kt");
|
||||
}
|
||||
|
||||
public void testExtensionWithImplicitReceiver() throws Exception {
|
||||
testFooBoxIsTrue("extensionWithImplicitReceiver.kt");
|
||||
}
|
||||
|
||||
public void testExtensionFunctionOnExpression() throws Exception {
|
||||
testFooBoxIsTrue("extensionFunctionOnExpression.kt");
|
||||
}
|
||||
|
||||
public void testExtensionUsedInsideClass() throws Exception {
|
||||
testFooBoxIsTrue("extensionUsedInsideClass.kt");
|
||||
}
|
||||
|
||||
public void testVirtualExtension() throws Exception {
|
||||
testFooBoxIsTrue("virtualExtension.kt");
|
||||
}
|
||||
|
||||
public void testVirtualExtensionOverride() throws Exception {
|
||||
testFooBoxIsTrue("virtualExtensionOverride.kt");
|
||||
}
|
||||
|
||||
public void testExtensionLiteralPassedToFunction() throws Exception {
|
||||
testFooBoxIsTrue("extensionLiteralPassedToFunction.kt");
|
||||
}
|
||||
|
||||
public void testExtensionInsideFunctionLiteral() throws Exception {
|
||||
testFooBoxIsTrue("extensionInsideFunctionLiteral.kt");
|
||||
}
|
||||
|
||||
public void testGenericExtension() throws Exception {
|
||||
testFooBoxIsOk("generic.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ExtensionPropertyTest extends TranslationTest {
|
||||
final private static String MAIN = "extensionProperty/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testSimplePropertyWithGetter() throws Exception {
|
||||
testFooBoxIsTrue("simplePropertyWithGetter.kt");
|
||||
}
|
||||
|
||||
public void testPropertyWithGetterAndSetter() throws Exception {
|
||||
testFooBoxIsTrue("propertyWithGetterAndSetter.kt");
|
||||
}
|
||||
|
||||
public void testAbsExtension() throws Exception {
|
||||
testFooBoxIsTrue("absExtension.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ForTest extends AbstractExpressionTest {
|
||||
|
||||
final private static String MAIN = "for/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testForIteratesOverArray() throws Exception {
|
||||
testFooBoxIsTrue("forIteratesOverArray.kt");
|
||||
}
|
||||
|
||||
public void testForOnEmptyArray() throws Exception {
|
||||
testFooBoxIsTrue("forOnEmptyArray.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class FunctionTest extends AbstractExpressionTest {
|
||||
|
||||
final private static String MAIN = "function/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testFunctionUsedBeforeDeclaration() throws Exception {
|
||||
testFooBoxIsTrue("functionUsedBeforeDeclaration.kt");
|
||||
}
|
||||
|
||||
public void testFunctionWithTwoParametersCall() throws Exception {
|
||||
testFooBoxIsTrue("functionWithTwoParametersCall.kt");
|
||||
}
|
||||
|
||||
public void testFunctionLiteral() throws Exception {
|
||||
testFooBoxIsTrue("functionLiteral.kt");
|
||||
}
|
||||
|
||||
public void testAdderClosure() throws Exception {
|
||||
testFooBoxIsTrue("adderClosure.kt");
|
||||
}
|
||||
|
||||
public void testLoopClosure() throws Exception {
|
||||
testFooBoxIsTrue("loopClosure.kt");
|
||||
}
|
||||
|
||||
public void testFunctionLiteralAsParameter() throws Exception {
|
||||
testFooBoxIsTrue("functionLiteralAsParameter.kt");
|
||||
}
|
||||
|
||||
public void testClosureWithParameter() throws Exception {
|
||||
testFooBoxIsOk("closureWithParameter.kt");
|
||||
}
|
||||
|
||||
public void testClosureWithParameterAndBoxing() throws Exception {
|
||||
testFooBoxIsOk("closureWithParameterAndBoxing.jet");
|
||||
}
|
||||
|
||||
public void testEnclosingThis() throws Exception {
|
||||
testFunctionOutput("enclosingThis.kt", "Anonymous", "box", "OK");
|
||||
}
|
||||
|
||||
|
||||
public void testImplicitItParameter() throws Exception {
|
||||
testFooBoxIsTrue("implicitItParameter.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testDefaultParameters() throws Exception {
|
||||
testFooBoxIsTrue("defaultParameters.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testFunctionLiteralAsLastParameter() throws Exception {
|
||||
testFooBoxIsTrue("functionLiteralAsLastParameter.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testNamedArguments() throws Exception {
|
||||
testFooBoxIsTrue("namedArguments.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testExpressionAsFunction() throws Exception {
|
||||
testFooBoxIsTrue("expressionAsFunction.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testVararg() throws Exception {
|
||||
testFooBoxIsTrue("vararg.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testkt921() throws Exception {
|
||||
try {
|
||||
checkOutput("KT-921.kt", "");
|
||||
} catch (Throwable e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void testFunctionInsideFunction() throws Exception {
|
||||
testFooBoxIsTrue("functionInsideFunction.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
public abstract class JavaClassesTest extends TranslationTest {
|
||||
|
||||
private final String SUITE = "java/";
|
||||
|
||||
@Override
|
||||
protected String suiteDirectoryName() {
|
||||
return SUITE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class KotlinLibTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "kotlinLib/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
private void runPropertyTypeCheck(String objectName, Map<String, Class<? extends Scriptable>> propertyToType)
|
||||
throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath()), new RhinoPropertyTypesChecker(objectName, propertyToType));
|
||||
}
|
||||
|
||||
|
||||
public void testKotlinJsLibRunsWithRhino() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath()), new RhinoResultChecker() {
|
||||
@Override
|
||||
public void runChecks(Context context, Scriptable scope) throws Exception {
|
||||
//do nothing
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//TODO: refactor
|
||||
public void testCreatedTraitIsJSObject() throws Exception {
|
||||
final Map<String, Class<? extends Scriptable>> propertyToType
|
||||
= new HashMap<String, Class<? extends Scriptable>>();
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("trait.js")),
|
||||
new RhinoPropertyTypesChecker("foo", propertyToType));
|
||||
}
|
||||
|
||||
|
||||
public void testCreatedNamespaceIsJSObject() throws Exception {
|
||||
final Map<String, Class<? extends Scriptable>> propertyToType
|
||||
= new HashMap<String, Class<? extends Scriptable>>();
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespace.js")),
|
||||
new RhinoPropertyTypesChecker("foo", propertyToType));
|
||||
}
|
||||
|
||||
//
|
||||
// TODO:Refactor calls to function result checker with test
|
||||
public void testNamespaceHasDeclaredFunction() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespace.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testNamespaceHasDeclaredClasses() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespaceWithClasses.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testIsSameType() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isSameType.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testIsAncestorType() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isAncestorType.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testIsComplexTest() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isComplexTest.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testCommaExpression() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("commaExpression.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testArray() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("array.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testHashMap() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("hashMap.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
* <p/>
|
||||
* This class contains tests that do not fall in any particular category
|
||||
* most probably because that functionality has very little support
|
||||
*/
|
||||
public final class MiscTest extends AbstractExpressionTest {
|
||||
final private static String MAIN = "misc/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testLocalPropertys() throws Exception {
|
||||
testFunctionOutput("localProperty.jet", "foo", "box", 50);
|
||||
}
|
||||
|
||||
public void testIntRange() throws Exception {
|
||||
// checkOutput("intRange.kt", " ");
|
||||
testFooBoxIsTrue("intRange.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testSafecallComputesExpressionOnlyOnce() throws Exception {
|
||||
testFooBoxIsTrue("safecallComputesExpressionOnlyOnce.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class MultiFileTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "multiFile/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testFunctionsVisibleFromOtherFile() throws Exception {
|
||||
testFooBoxIsTrue("functionsVisibleFromOtherFile");
|
||||
}
|
||||
|
||||
public void testClassesInheritedFromOtherFile() throws Exception {
|
||||
testFooBoxIsTrue("classesInheritedFromOtherFile");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testFooBoxIsTrue(String dirName) throws Exception {
|
||||
testMultiFile(dirName, "foo", "box", true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class MultiNamespaceTest extends TranslationTest {
|
||||
final private static String MAIN = "multiNamespace/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testFunctionsVisibleFromOtherNamespace() throws Exception {
|
||||
testFooBoxIsTrue("functionsVisibleFromOtherNamespace");
|
||||
}
|
||||
|
||||
public void testClassesInheritedFromOtherNamespace() throws Exception {
|
||||
testFooBoxIsTrue("classesInheritedFromOtherNamespace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testFooBoxIsTrue(String dirName) throws Exception {
|
||||
testMultiFile(dirName, "foo", "box", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class NameClashesTest extends TranslationTest {
|
||||
|
||||
private static final String MAIN = "nameClashes/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testMethodOverload() throws Exception {
|
||||
testFooBoxIsTrue("methodOverload.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ObjectTest extends TranslationTest {
|
||||
|
||||
private static final String MAIN = "object/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testObjectWithMethods() throws Exception {
|
||||
testFooBoxIsTrue("objectWithMethods.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testObjectDeclaration() throws Exception {
|
||||
testFooBoxIsTrue("objectDeclaration.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testObjectInMethod() throws Exception {
|
||||
testFooBoxIsTrue("objectInMethod.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class OperatorOverloadingTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "operatorOverloading/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testPlusOverload() throws Exception {
|
||||
testFooBoxIsTrue("plusOverload.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testPostfixInc() throws Exception {
|
||||
testFooBoxIsTrue("postfixIncOverload.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testPrefixDecOverload() throws Exception {
|
||||
testFooBoxIsTrue("prefixDecOverload.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testPrefixIncReturnsCorrectValue() throws Exception {
|
||||
testFooBoxIsTrue("prefixIncReturnsCorrectValue.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testOverloadedCallOnProperty() throws Exception {
|
||||
testFooBoxIsTrue("overloadedCallOnProperty.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testPostfixOnProperty() throws Exception {
|
||||
testFooBoxIsTrue("postfixOnProperty.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testOperatorOverloadOnPropertyCallGetterAndSetterOnlyOnce() throws Exception {
|
||||
testFooBoxIsTrue("operatorOverloadOnPropertyCallGetterAndSetterOnlyOnce.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testUnaryOnIntProperty() throws Exception {
|
||||
testFooBoxIsTrue("unaryOnIntProperty.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testUnaryOnIntPropertyAsStatement() throws Exception {
|
||||
testFooBoxIsTrue("unaryOnIntProperty2.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testBinaryDivOverload() throws Exception {
|
||||
testFooBoxIsTrue("binaryDivOverload.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testPlusAssignNoReassign() throws Exception {
|
||||
testFooBoxIsTrue("plusAssignNoReassign.kt");
|
||||
}
|
||||
|
||||
public void testNotOverload() throws Exception {
|
||||
testFooBoxIsTrue("notOverload.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testCompareTo() throws Exception {
|
||||
testFooBoxIsTrue("compareTo.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testPlusAndMinusAsAnExpression() throws Exception {
|
||||
testFooBoxIsTrue("plusAndMinusAsAnExpression.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testUsingModInCaseModAssignNotAvailable() throws Exception {
|
||||
testFooBoxIsTrue("usingModInCaseModAssignNotAvailable.kt");
|
||||
}
|
||||
|
||||
public void testOverloadPlusAssignArrayList() throws Exception {
|
||||
testFooBoxIsOk("overloadPlusAssignArrayList.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.mozilla.javascript.JavaScriptException;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class PatternMatchingTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "patternMatching/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testWhenType() throws Exception {
|
||||
testFooBoxIsTrue("whenType.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testWhenNotType() throws Exception {
|
||||
testFooBoxIsTrue("whenNotType.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testWhenExecutesOnlyOnce() throws Exception {
|
||||
testFooBoxIsTrue("whenExecutesOnlyOnce.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testWhenValue() throws Exception {
|
||||
testFooBoxIsTrue("whenValue.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testWhenNotValue() throws Exception {
|
||||
testFooBoxIsTrue("whenNotValue.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testWhenValueOrType() throws Exception {
|
||||
testFooBoxIsTrue("whenValueOrType.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testWhenWithIf() throws Exception {
|
||||
testFooBoxIsTrue("whenWithIf.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testMultipleCases() throws Exception {
|
||||
testFunctionOutput("multipleCases.kt", "foo", "box", 2.0);
|
||||
}
|
||||
|
||||
|
||||
public void testMatchNullableType() throws Exception {
|
||||
testFooBoxIsTrue("matchNullableType.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testWhenAsExpression() throws Exception {
|
||||
testFooBoxIsTrue("whenAsExpression.kt");
|
||||
}
|
||||
|
||||
public void whenAsExpressionWithThrow() throws Exception {
|
||||
try {
|
||||
testFooBoxIsTrue("whenAsExpressionWithThrow.kt");
|
||||
fail();
|
||||
} catch (JavaScriptException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class PropertyAccessTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "propertyAccess/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testAccessToInstanceProperty() throws Exception {
|
||||
testFooBoxIsTrue("accessToInstanceProperty.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testTwoClassesWithProperties() throws Exception {
|
||||
testFooBoxIsTrue("twoClassesWithProperties.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testSetter() throws Exception {
|
||||
testFunctionOutput("setter.kt", "foo", "f", 99.0);
|
||||
}
|
||||
|
||||
|
||||
public void testCustomGetter() throws Exception {
|
||||
testFooBoxIsTrue("customGetter.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testCustomSetter() throws Exception {
|
||||
testFooBoxIsTrue("customSetter.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testSafeCall() throws Exception {
|
||||
testFooBoxIsTrue("safeCall.kt");
|
||||
}
|
||||
|
||||
|
||||
//TODO: place safecalls under distinkt category
|
||||
public void testSafeCallReturnsNullIfFails() throws Exception {
|
||||
testFooBoxIsTrue("safeCallReturnsNullIfFails.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testNamespacePropertyInitializer() throws Exception {
|
||||
testFooBoxIsTrue("namespacePropertyInitializer.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testNamespacePropertySet() throws Exception {
|
||||
testFooBoxIsTrue("namespacePropertySet.kt");
|
||||
}
|
||||
|
||||
public void testNamespaceCustomAccessors() throws Exception {
|
||||
testFooBoxIsTrue("namespaceCustomAccessors.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testClassUsesNamespaceProperties() throws Exception {
|
||||
testFooBoxIsTrue("classUsesNamespaceProperties.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testSafeAccess() throws Exception {
|
||||
testFooBoxIsTrue("safeAccess.kt");
|
||||
}
|
||||
|
||||
public void testSafeExtensionFunctionCall() throws Exception {
|
||||
testFooBoxIsOk("safeExtensionFunctionCall.kt");
|
||||
}
|
||||
|
||||
public void testExtensionLiteralSafeCall() throws Exception {
|
||||
testFooBoxIsTrue("extensionLiteralSafeCall.kt");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class RTTITest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "rtti/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testIsSameClass() throws Exception {
|
||||
testFooBoxIsTrue("isSameClass.kt");
|
||||
}
|
||||
|
||||
public void testNotIsOtherClass() throws Exception {
|
||||
testFooBoxIsTrue("notIsOtherClass.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class RangeTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "range/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testExplicitRange() throws Exception {
|
||||
testFooBoxIsTrue("explicitRange.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testRangeSugarSyntax() throws Exception {
|
||||
testFooBoxIsTrue("rangeSugarSyntax.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testIntInRange() throws Exception {
|
||||
testFooBoxIsTrue("intInRange.kt");
|
||||
}
|
||||
|
||||
public void testIteratingOverRanges() throws Exception {
|
||||
testFooBoxIsTrue("iteratingOverRanges.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
|
||||
private final String namespaceName;
|
||||
private final String functionName;
|
||||
private final Object expectedResult;
|
||||
|
||||
public RhinoFunctionResultChecker(@Nullable String namespaceName, String functionName, Object expectedResult) {
|
||||
this.namespaceName = namespaceName;
|
||||
this.functionName = functionName;
|
||||
this.expectedResult = expectedResult;
|
||||
}
|
||||
|
||||
public RhinoFunctionResultChecker(String functionName, Object expectedResult) {
|
||||
this(null, functionName, expectedResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runChecks(Context context, Scriptable scope) throws Exception {
|
||||
Object result = evaluateFunction(context, scope);
|
||||
assertTrue("Result is not what expected! Expected: " + expectedResult + " Evaluated : " + result,
|
||||
result.equals(expectedResult));
|
||||
String report = namespaceName + "." + functionName + "() = " + Context.toString(result);
|
||||
System.out.println(report);
|
||||
}
|
||||
|
||||
private Object evaluateFunction(Context cx, Scriptable scope) {
|
||||
return cx.evaluateString(scope, functionCallString(), "function call", 0, null);
|
||||
}
|
||||
|
||||
private String functionCallString() {
|
||||
String result = functionName + "()";
|
||||
if (namespaceName != null) {
|
||||
result = namespaceName + "." + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.NativeObject;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class RhinoPropertyTypesChecker implements RhinoResultChecker {
|
||||
|
||||
final private String objectName;
|
||||
final private Map<String, Class<? extends Scriptable>> propertyToType;
|
||||
|
||||
public RhinoPropertyTypesChecker(String objectName, Map<String, Class<? extends Scriptable>> propertyToType) {
|
||||
this.objectName = objectName;
|
||||
this.propertyToType = propertyToType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runChecks(Context context, Scriptable scope) throws Exception {
|
||||
NativeObject object = RhinoUtils.extractObject(objectName, scope);
|
||||
verifyObjectHasExpectedPropertiesOfExpectedTypes(object, propertyToType);
|
||||
}
|
||||
|
||||
private void verifyObjectHasExpectedPropertiesOfExpectedTypes
|
||||
(NativeObject object, Map<String, Class<? extends Scriptable>> nameToClassMap) {
|
||||
for (Map.Entry<String, Class<? extends Scriptable>> entry : nameToClassMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Class expectedClass = entry.getValue();
|
||||
assertTrue(object + " must contain key " + name, object.containsKey(name));
|
||||
assertTrue(object + "'s property " + name + " must be of type " + expectedClass,
|
||||
expectedClass.isInstance(object.get(name)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public interface RhinoResultChecker {
|
||||
public void runChecks(Context context, Scriptable scope) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.utils.GenerationUtils;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class RhinoSystemOutputChecker implements RhinoResultChecker {
|
||||
|
||||
private final List<String> arguments;
|
||||
private final String expectedResult;
|
||||
|
||||
public RhinoSystemOutputChecker(String expectedResult, List<String> arguments) {
|
||||
this.expectedResult = expectedResult;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runChecks(@NotNull Context context, @NotNull Scriptable scope)
|
||||
throws Exception {
|
||||
runMain(context, scope);
|
||||
String result = getSystemOutput(context, scope);
|
||||
String trimmedExpected = trimSpace(expectedResult);
|
||||
String trimmedActual = trimSpace(result);
|
||||
// System.out.println(trimmedActual);
|
||||
// System.out.println(trimmedExpected);
|
||||
assertTrue("Returned:\n" + trimmedActual + "END_OF_RETURNED\nExpected:\n" + trimmedExpected
|
||||
+ "END_OF_EXPECTED\n", trimmedExpected.equals(trimmedActual));
|
||||
}
|
||||
|
||||
private String getSystemOutput(@NotNull Context context, @NotNull Scriptable scope) {
|
||||
Object output = context.evaluateString(scope, "Kotlin.System.output()", "test", 0, null);
|
||||
assertTrue("Output should be a string.", output instanceof String);
|
||||
return (String) output;
|
||||
}
|
||||
|
||||
private void runMain(Context context, Scriptable scope) {
|
||||
String callToMain = GenerationUtils.generateCallToMain("Anonymous", arguments);
|
||||
context.evaluateString(scope, callToMain, "function call", 0, null);
|
||||
}
|
||||
|
||||
public String trimSpace(String s) {
|
||||
String[] choppedUpString = s.trim().split("\\s");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String word : choppedUpString) {
|
||||
sb.append(word);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.mozilla.javascript.NativeObject;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class RhinoUtils {
|
||||
|
||||
private RhinoUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static NativeObject extractObject(String objectName, Scriptable scope) {
|
||||
Object nativeObject = scope.get(objectName, scope);
|
||||
assertTrue(objectName + " should be JSON Object", nativeObject instanceof NativeObject);
|
||||
return (NativeObject) nativeObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class SimpleTestSuite extends UsefulTestCase {
|
||||
|
||||
public static Test suite() {
|
||||
return Suite.suiteForDirectory("simple/", new Suite.SingleFileTester() {
|
||||
@Override
|
||||
public void performTest(@NotNull Suite test, @NotNull String filename) throws Exception {
|
||||
test.testFooBoxIsTrue(filename);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class StandardClassesTest extends TranslationTest {
|
||||
final private static String MAIN = "standardClasses/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testArray() throws Exception {
|
||||
testFooBoxIsTrue("array.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testArrayAccess() throws Exception {
|
||||
testFooBoxIsTrue("arrayAccess.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testArrayIsFilledWithNulls() throws Exception {
|
||||
testFooBoxIsTrue("arrayIsFilledWithNulls.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testArrayFunctionConstructor() throws Exception {
|
||||
testFooBoxIsTrue("arrayFunctionConstructor.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testArraySize() throws Exception {
|
||||
testFooBoxIsTrue("arraySize.kt");
|
||||
}
|
||||
|
||||
//TODO: this feature in not supported for some time
|
||||
//TODO: support it. Probably configurable.
|
||||
// (expected = JavaScriptException.class)
|
||||
// public void arrayThrowsExceptionOnOOBaccess() throws Exception {
|
||||
// testFooBoxIsTrue("arrayThrowsExceptionOnOOBaccess.kt");
|
||||
// }
|
||||
|
||||
|
||||
public void testArraysIterator() throws Exception {
|
||||
testFooBoxIsTrue("arraysIterator.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class StringTest extends AbstractExpressionTest {
|
||||
|
||||
final private static String MAIN = "string/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testStringConstant() throws Exception {
|
||||
testFooBoxIsTrue("stringConstant.kt");
|
||||
}
|
||||
|
||||
public void testStringAssignment() throws Exception {
|
||||
testFooBoxIsTrue("stringAssignment.kt");
|
||||
}
|
||||
|
||||
public void testIntInTemplate() throws Exception {
|
||||
testFunctionOutput("intInTemplate.kt", "foo", "box", "my age is 3");
|
||||
}
|
||||
|
||||
public void testStringInTemplate() throws Exception {
|
||||
testFunctionOutput("stringInTemplate.kt", "foo", "box", "oHelloo");
|
||||
}
|
||||
|
||||
public void testMultipleExpressionInTemplate() throws Exception {
|
||||
testFunctionOutput("multipleExpressionsInTemplate.kt", "foo", "box", "left = 3\nright = 2\nsum = 5\n");
|
||||
}
|
||||
|
||||
public void testToStringMethod() throws Exception {
|
||||
testFooBoxIsTrue("objectToStringCallInTemplate.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
//TODO: this class has strange behaviour. Should be refactored.
|
||||
public final class Suite extends TranslationTest {
|
||||
|
||||
private String name;
|
||||
private final SingleFileTester tester;
|
||||
private final String testMain;
|
||||
|
||||
public Suite(@NotNull String testName,
|
||||
@NotNull String suiteDirName,
|
||||
@NotNull final SingleFileTester tester) {
|
||||
this.name = testName;
|
||||
this.tester = tester;
|
||||
this.testMain = suiteDirName;
|
||||
}
|
||||
|
||||
public Suite() {
|
||||
this("dummy", "dummy", new SingleFileTester() {
|
||||
@Override
|
||||
public void performTest(@NotNull Suite test, @NotNull String filename) throws Exception {
|
||||
//do nothing
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//NOTE: just to avoid warning
|
||||
public void testNothing() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return testMain;
|
||||
}
|
||||
|
||||
public void runTest() throws Exception {
|
||||
tester.performTest(this, name);
|
||||
}
|
||||
|
||||
public static Test suiteForDirectory(@NotNull final String mainName, @NotNull final SingleFileTester testMethod) {
|
||||
|
||||
return TranslatorTestCaseBuilder.suiteForDirectory("translator\\testFiles\\",
|
||||
mainName + casesDirectoryName(), true, new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String name) {
|
||||
return (new Suite(name, mainName, testMethod));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected static interface SingleFileTester {
|
||||
void performTest(@NotNull Suite test, @NotNull String filename) throws Exception;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class TraitTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "trait/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testTraitAddsFunctionsToClass() throws Exception {
|
||||
testFooBoxIsTrue("traitAddsFunctionsToClass.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testClassDerivesFromClassAndTrait() throws Exception {
|
||||
testFooBoxIsTrue("classDerivesFromClassAndTrait.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testClassDerivesFromTraitAndClass() throws Exception {
|
||||
testFooBoxIsTrue("classDerivesFromTraitAndClass.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testExample() throws Exception {
|
||||
testFooBoxIsTrue("example.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testTraitExtendsTrait() throws Exception {
|
||||
testFooBoxIsTrue("traitExtendsTrait.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testTraitExtendsTwoTraits() throws Exception {
|
||||
testFooBoxIsTrue("traitExtendsTwoTraits.kt");
|
||||
}
|
||||
|
||||
|
||||
public void testFunDelegation() throws Exception {
|
||||
testFooBoxIsOk("funDelegation.jet");
|
||||
}
|
||||
|
||||
|
||||
public void testDefinitionOrder() throws Exception {
|
||||
testFooBoxIsTrue("definitionOrder.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
//TODO: spread the test* methods amongst classes that actually use them
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class TranslationTest extends BaseTest {
|
||||
|
||||
private final static String TEST_FILES = "translator/testFiles/";
|
||||
private static final String CASES = "cases/";
|
||||
private static final String OUT = "out/";
|
||||
private static final String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
|
||||
private static final String EXPECTED = "expected/";
|
||||
|
||||
protected String kotlinLibraryPath() {
|
||||
return KOTLIN_JS_LIB;
|
||||
}
|
||||
|
||||
protected static String casesDirectoryName() {
|
||||
return CASES;
|
||||
}
|
||||
|
||||
private static String outDirectoryName() {
|
||||
return OUT;
|
||||
}
|
||||
|
||||
protected abstract String mainDirectory();
|
||||
|
||||
private String testFilesPath() {
|
||||
return TEST_FILES + suiteDirectoryName() + mainDirectory();
|
||||
}
|
||||
|
||||
protected String suiteDirectoryName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getOutputPath() {
|
||||
return testFilesPath() + outDirectoryName();
|
||||
}
|
||||
|
||||
protected String getInputPath() {
|
||||
return testFilesPath() + casesDirectoryName();
|
||||
}
|
||||
|
||||
private String getExpectedPath() {
|
||||
return testFilesPath() + expectedDirectoryName();
|
||||
}
|
||||
|
||||
private String expectedDirectoryName() {
|
||||
return EXPECTED;
|
||||
}
|
||||
|
||||
protected void testFunctionOutput(String filename, String namespaceName,
|
||||
String functionName, Object expectedResult) throws Exception {
|
||||
translateFile(filename);
|
||||
runRhinoTest(generateFilenameList(getOutputFilePath(filename)),
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
protected void testMultiFile(String dirName, String namespaceName,
|
||||
String functionName, Object expectedResult) throws Exception {
|
||||
translateFilesInDir(dirName);
|
||||
runRhinoTest(generateFilenameList(getOutputFilePath(dirName + ".kt")),
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
protected void translateFile(String filename) throws Exception {
|
||||
K2JSTranslator.testTranslateFile(getInputFilePath(filename),
|
||||
getOutputFilePath(filename));
|
||||
}
|
||||
|
||||
protected void translateFilesInDir(String dirName) throws Exception {
|
||||
String dirPath = getInputFilePath(dirName);
|
||||
File dir = new File(dirPath);
|
||||
List<String> fullFilePaths = new ArrayList<String>();
|
||||
for (String fileName : dir.list()) {
|
||||
fullFilePaths.add(getInputFilePath(dirName) + "\\" + fileName);
|
||||
}
|
||||
assert dir.isDirectory();
|
||||
K2JSTranslator.testTranslateFiles(fullFilePaths,
|
||||
getOutputFilePath(dirName + ".kt"));
|
||||
}
|
||||
|
||||
protected List<String> generateFilenameList(String inputFile) {
|
||||
return Arrays.asList(kotlinLibraryPath(), inputFile);
|
||||
}
|
||||
|
||||
//TODO: refactor filename generation logic
|
||||
protected String getOutputFilePath(String filename) {
|
||||
return getOutputPath() + convertToDotJsFile(filename);
|
||||
}
|
||||
|
||||
private String convertToDotJsFile(String filename) {
|
||||
return filename.substring(0, filename.lastIndexOf('.')) + ".js";
|
||||
}
|
||||
|
||||
private String getInputFilePath(String filename) {
|
||||
return getInputPath() + filename;
|
||||
}
|
||||
|
||||
protected String cases(String filename) {
|
||||
return getInputFilePath(filename);
|
||||
}
|
||||
|
||||
private String expected(String testName) {
|
||||
return getExpectedPath() + testName + ".out";
|
||||
}
|
||||
|
||||
protected void runFileWithRhino(String inputFile, Context context, Scriptable scope) throws Exception {
|
||||
FileReader reader = new FileReader(inputFile);
|
||||
context.evaluateReader(scope, reader, inputFile, 1, null);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
protected void runRhinoTest(List<String> fileNames, RhinoResultChecker checker) throws Exception {
|
||||
Context context = Context.enter();
|
||||
Scriptable scope = context.initStandardObjects();
|
||||
for (String filename : fileNames) {
|
||||
runFileWithRhino(filename, context, scope);
|
||||
}
|
||||
checker.runChecks(context, scope);
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
public void testFooBoxIsTrue(String filename) throws Exception {
|
||||
testFunctionOutput(filename, "foo", "box", true);
|
||||
}
|
||||
|
||||
public void testFooBoxIsOk(String filename) throws Exception {
|
||||
testFunctionOutput(filename, "foo", "box", "OK");
|
||||
}
|
||||
|
||||
protected void checkOutput(String filename, String expectedResult, String... args) throws Exception {
|
||||
translateFile(filename);
|
||||
runRhinoTest(generateFilenameList(getOutputFilePath(filename)),
|
||||
new RhinoSystemOutputChecker(expectedResult, Arrays.asList(args)));
|
||||
}
|
||||
|
||||
protected void testWithMain(String testName, String testId, String... args) throws Exception {
|
||||
checkOutput(testName + ".kt", readFile(expected(testName + testId)), args);
|
||||
}
|
||||
|
||||
private static String readFile(String path) throws IOException {
|
||||
FileInputStream stream = new FileInputStream(new File(path));
|
||||
try {
|
||||
FileChannel fc = stream.getChannel();
|
||||
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
|
||||
/* Instead of using default, pass in a decoder. */
|
||||
return Charset.defaultCharset().decode(bb).toString();
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class TranslatorTestCaseBuilder {
|
||||
public static FilenameFilter emptyFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public interface NamedTestFactory {
|
||||
@NotNull
|
||||
Test createTest(@NotNull String filename);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath,
|
||||
boolean recursive, @NotNull NamedTestFactory factory) {
|
||||
return suiteForDirectory(baseDataDir, dataPath, recursive, emptyFilter, factory);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive,
|
||||
final FilenameFilter filter, @NotNull NamedTestFactory factory) {
|
||||
TestSuite suite = new TestSuite(dataPath);
|
||||
appendTestsInDirectory(baseDataDir, dataPath, recursive, filter, factory, suite);
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static void appendTestsInDirectory(String baseDataDir, String dataPath, boolean recursive,
|
||||
final FilenameFilter filter, NamedTestFactory factory, TestSuite suite) {
|
||||
final String extensionJet = ".jet";
|
||||
final String extensionKt = ".kt";
|
||||
final FilenameFilter extensionFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(extensionJet) || name.endsWith(extensionKt);
|
||||
}
|
||||
};
|
||||
FilenameFilter resultFilter;
|
||||
if (filter != emptyFilter) {
|
||||
resultFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String s) {
|
||||
return extensionFilter.accept(file, s) && filter.accept(file, s);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
resultFilter = extensionFilter;
|
||||
}
|
||||
File dir = new File(baseDataDir + dataPath);
|
||||
FileFilter dirFilter = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.isDirectory();
|
||||
}
|
||||
};
|
||||
if (recursive) {
|
||||
File[] files = dir.listFiles(dirFilter);
|
||||
assert files != null : dir;
|
||||
List<File> subdirs = Arrays.asList(files);
|
||||
Collections.sort(subdirs);
|
||||
for (File subdir : subdirs) {
|
||||
suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory));
|
||||
}
|
||||
}
|
||||
List<File> files = Arrays.asList(dir.listFiles(resultFilter));
|
||||
Collections.sort(files);
|
||||
for (File file : files) {
|
||||
String fileName = file.getName();
|
||||
assert fileName != null;
|
||||
String extension = fileName.endsWith(extensionJet) ? extensionJet : extensionKt;
|
||||
suite.addTest(factory.createTest(fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class TupleTest extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "tuple/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testTwoElements() throws Exception {
|
||||
testFooBoxIsTrue("twoElements.kt");
|
||||
}
|
||||
|
||||
public void testMultipleMembers() throws Exception {
|
||||
testFooBoxIsTrue("multipleMembers.kt");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class WebDemoExamples1Test extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "webDemoExamples1/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
|
||||
public void testPrintArg() throws Exception {
|
||||
checkOutput("printArg.kt", "Hello, world!", "Hello, world!");
|
||||
}
|
||||
|
||||
|
||||
public void testWhileLoop() throws Exception {
|
||||
checkOutput("whileLoop.kt", "guest1\nguest2\nguest3\nguest4\n", "guest1", "guest2", "guest3", "guest4");
|
||||
}
|
||||
|
||||
|
||||
public void testIfAsExpression() throws Exception {
|
||||
checkOutput("ifAsExpression.kt", "20\n", "10", "20");
|
||||
}
|
||||
|
||||
|
||||
public void testObjectOrientedHello() throws Exception {
|
||||
checkOutput("objectOrientedHello.kt", "Hello, Pavel!\n", "Pavel");
|
||||
}
|
||||
|
||||
|
||||
public void testMultiLanguageHello() throws Exception {
|
||||
checkOutput("multiLanguageHello.kt", "Salut!\n", "FR");
|
||||
}
|
||||
|
||||
|
||||
public void testNullChecks() throws Exception {
|
||||
checkOutput("nullChecks.kt", "No number supplied");
|
||||
checkOutput("nullChecks.kt", "6", "2", "3");
|
||||
}
|
||||
|
||||
|
||||
public void testRanges() throws Exception {
|
||||
checkOutput("ranges.kt", "OK\n" +
|
||||
" 1 2 3 4 5\n" +
|
||||
"Out: array has only 3 elements. x = 4\n" +
|
||||
"Yes: array contains aaa\n" +
|
||||
"No: array doesn't contains ddd\n", "4");
|
||||
|
||||
checkOutput("ranges.kt", " 1 2 3 4 5\n" +
|
||||
"Out: array has only 3 elements. x = 10\n" +
|
||||
"Yes: array contains aaa\n" +
|
||||
"No: array doesn't contains ddd\n", "10");
|
||||
}
|
||||
|
||||
|
||||
public void testForLoop() throws Exception {
|
||||
checkOutput("forLoop.kt", "a\n" +
|
||||
"b\n" +
|
||||
"c\n" +
|
||||
"\n" +
|
||||
"a\n" +
|
||||
"b\n" +
|
||||
"c\n", "a", "b", "c");
|
||||
checkOutput("forLoop.kt", "123\n\n123\n", "123");
|
||||
}
|
||||
|
||||
|
||||
public void testIsCheck() throws Exception {
|
||||
checkOutput("isCheck.kt", "3\nnull\n");
|
||||
}
|
||||
|
||||
|
||||
public void testPatternMatching() throws Exception {
|
||||
checkOutput("patternMatching.kt", "Greeting\n" +
|
||||
"One\n" +
|
||||
"Not a string\n" +
|
||||
"Unknown\n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class WebDemoExamples2Test extends TranslationTest {
|
||||
|
||||
final private static String MAIN = "webDemoExamples2/";
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return MAIN;
|
||||
}
|
||||
|
||||
public void testBottles() throws Exception {
|
||||
testWithMain("bottles", "2", "2");
|
||||
testWithMain("bottles", "");
|
||||
}
|
||||
|
||||
public void testLife() throws Exception {
|
||||
testWithMain("life", "", "2");
|
||||
}
|
||||
|
||||
public void testBuilder() throws Exception {
|
||||
testWithMain("builder", "");
|
||||
testWithMain("builder", "1", "over9000");
|
||||
}
|
||||
|
||||
//TODO: comparator LinkedList dependencies
|
||||
// @Test
|
||||
// public void maze() throws Exception {
|
||||
// testWithMain("maze", "");
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user