JS test: added multi-module inline tests

This commit is contained in:
Alexey Tsvetkov
2015-05-19 21:03:31 +03:00
parent 115798f584
commit fc1a1f742b
24 changed files with 280 additions and 0 deletions
@@ -854,6 +854,10 @@ fun main(args: Array<String>) {
model("inlineEvaluationOrder/cases")
}
testClass(javaClass<AbstractInlineMultiModuleTest>()) {
model("inlineMultiModule/cases", extension = null, recursive=false)
}
testClass(javaClass<AbstractLabelTest>()) {
model("labels/cases")
}
@@ -0,0 +1,97 @@
/*
* Copyright 2010-2015 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.kotlin.js.test.semantics;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("js/js.translator/testData/inlineMultiModule/cases")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class InlineMultiModuleTestGenerated extends AbstractInlineMultiModuleTest {
public void testAllFilesPresentInCases() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/inlineMultiModule/cases"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("anotherModuleValInClosure")
public void testAnotherModuleValInClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/anotherModuleValInClosure/");
doTest(fileName);
}
@TestMetadata("callableReference")
public void testCallableReference() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/callableReference/");
doTest(fileName);
}
@TestMetadata("calledByFqName")
public void testCalledByFqName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/calledByFqName/");
doTest(fileName);
}
@TestMetadata("extensionLambda")
public void testExtensionLambda() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/extensionLambda/");
doTest(fileName);
}
@TestMetadata("lambda")
public void testLambda() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/lambda/");
doTest(fileName);
}
@TestMetadata("lambdaCalledInObjectLiteral")
public void testLambdaCalledInObjectLiteral() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/lambdaCalledInObjectLiteral/");
doTest(fileName);
}
@TestMetadata("lambdaWithClosure")
public void testLambdaWithClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/lambdaWithClosure/");
doTest(fileName);
}
@TestMetadata("localNameClash")
public void testLocalNameClash() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/localNameClash/");
doTest(fileName);
}
@TestMetadata("method")
public void testMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/method/");
doTest(fileName);
}
@TestMetadata("simple")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineMultiModule/cases/simple/");
doTest(fileName);
}
}
@@ -46,4 +46,6 @@ public abstract class AbstractLabelTest : AbstractSingleFileTranslationWithDirec
public abstract class AbstractMultiModuleTest : MultipleModulesTranslationTest("multiModule/")
public abstract class AbstractInlineMultiModuleTest : MultipleModulesTranslationTest("inlineMultiModule/")
public abstract class AbstractReservedWordTest : SingleFileTranslationTest("reservedWords/")
@@ -0,0 +1,9 @@
package utils
public var LOG: String = ""
inline
public fun log(s: String): String {
LOG += s
return LOG
}
@@ -0,0 +1,12 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
fun test(s: String): String = log(s + ";")
fun box(): String {
assertEquals("a;", test("a"))
assertEquals("a;b;", test("b"))
return "OK"
}
@@ -0,0 +1,5 @@
package utils
inline
public fun apply<T, R>(x: T, fn: (T)->R): R =
fn(x)
@@ -0,0 +1,13 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
fun multiplyBy2(x: Int): Int = x * 2
fun test(x: Int): Int = apply(x, ::multiplyBy2)
fun box(): String {
assertEquals(6, test(3))
return "OK"
}
@@ -0,0 +1,5 @@
package utils
inline
public fun sum(x: Int, y: Int): Int =
x + y
@@ -0,0 +1,10 @@
// CHECK_CONTAINS_NO_CALLS: test
fun test(x: Int, y: Int): Int = utils.sum(x, y)
fun box(): String {
assertEquals(3, test(1, 2))
assertEquals(5, test(2, 3))
return "OK"
}
@@ -0,0 +1,5 @@
package utils
inline
public fun apply<T, R>(x: T, fn: T.()->R): R =
x.fn()
@@ -0,0 +1,13 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
class A(val n: Int)
fun test(a: A, m: Int): Int = apply(a) { n * m }
fun box(): String {
assertEquals(6, test(A(2), 3))
return "OK"
}
@@ -0,0 +1,5 @@
package utils
inline
public fun apply<T, R>(x: T, fn: (T)->R): R =
fn(x)
@@ -0,0 +1,11 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
fun test(x: Int): Int = apply(x) { it * 2 }
fun box(): String {
assertEquals(6, test(3))
return "OK"
}
@@ -0,0 +1,10 @@
package utils
inline
public fun apply<T, R>(x: T, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) fn: (T)->R): R {
val result = object {
val x = fn(x)
}
return result.x
}
@@ -0,0 +1,9 @@
import utils.*
fun test(x: Int): Int = apply(x) { it * 2 }
fun box(): String {
assertEquals(6, test(3))
return "OK"
}
@@ -0,0 +1,5 @@
package utils
inline
public fun apply<T, R>(x: T, fn: (T)->R): R =
fn(x)
@@ -0,0 +1,11 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
fun test(x: Int, y: Int): Int = apply(x) { it + y }
fun box(): String {
assertEquals(3, test(1, 2))
return "OK"
}
@@ -0,0 +1,7 @@
package utils
inline
public fun apply<T, R>(x: T, fn: (T)->R): R {
val y = fn(x)
return y
}
@@ -0,0 +1,11 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
fun test(x: Int, y: Int): Int = apply(x) { it + 1 } * y
fun box(): String {
assertEquals(6, test(1, 3))
return "OK"
}
@@ -0,0 +1,6 @@
package utils
public class A(public val x: Int) {
inline
public fun plus(y: Int): Int = x + y
}
@@ -0,0 +1,11 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
fun test(a: A, y: Int): Int = a.plus(y)
fun box(): String {
assertEquals(5, test(A(2), 3))
return "OK"
}
@@ -0,0 +1,5 @@
package utils
inline
public fun sum(x: Int, y: Int): Int =
x + y
@@ -0,0 +1,12 @@
import utils.*
// CHECK_CONTAINS_NO_CALLS: test
fun test(x: Int, y: Int): Int = sum(x, y)
fun box(): String {
assertEquals(3, test(1, 2))
assertEquals(5, test(2, 3))
return "OK"
}
@@ -0,0 +1,2 @@
lib->
main->lib