JS: added inline stdlib cases

This commit is contained in:
Alexey Tsvetkov
2015-03-04 17:47:23 +03:00
parent 38efec6886
commit 53dfd77d31
10 changed files with 263 additions and 0 deletions
@@ -797,6 +797,10 @@ fun main(args: Array<String>) {
model("inline/cases")
}
testClass(javaClass<AbstractInlineJsStdlibTest>()) {
model("inlineStdlib/cases")
}
testClass(javaClass<AbstractLabelTest>()) {
model("labels/cases")
}
@@ -0,0 +1,25 @@
/*
* 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 org.jetbrains.kotlin.js.test.AbstractSingleFileTranslationWithDirectivesTest;
public abstract class AbstractInlineJsStdlibTest extends AbstractSingleFileTranslationWithDirectivesTest {
public AbstractInlineJsStdlibTest() {
super("inlineStdlib/");
}
}
@@ -0,0 +1,80 @@
/*
* 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.InnerTestClasses;
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/inlineStdlib/cases")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class InlineJsStdlibTestGenerated extends AbstractInlineJsStdlibTest {
public void testAllFilesPresentInCases() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/inlineStdlib/cases"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("callNameClash.kt")
public void testCallNameClash() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineStdlib/cases/callNameClash.kt");
doTest(fileName);
}
@TestMetadata("closure.kt")
public void testClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineStdlib/cases/closure.kt");
doTest(fileName);
}
@TestMetadata("closureInObjectLiteral.kt")
public void testClosureInObjectLiteral() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineStdlib/cases/closureInObjectLiteral.kt");
doTest(fileName);
}
@TestMetadata("closureNested.kt")
public void testClosureNested() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineStdlib/cases/closureNested.kt");
doTest(fileName);
}
@TestMetadata("localNamesClash.kt")
public void testLocalNamesClash() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineStdlib/cases/localNamesClash.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineStdlib/cases/simple.kt");
doTest(fileName);
}
@TestMetadata("thisInExtension.kt")
public void testThisInExtension() throws Exception {
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineStdlib/cases/thisInExtension.kt");
doTest(fileName);
}
}
@@ -0,0 +1,27 @@
package foo
// CHECK_NOT_CALLED: with_dbz3ex
fun f(x: Int): Int = x * 2
fun Int.f(): Int = this * 3
class A(var value: Int) {
class object {
fun f(): Int = 5
}
fun f(): Int = value
}
fun test(a: A): Int =
// TODO: check that with second parameter is named f?
with (a) {
f(f() + A.f()).f()
}
fun box(): String {
assertEquals(90, test(A(10)))
return "OK"
}
@@ -0,0 +1,21 @@
package foo
// CHECK_CONTAINS_NO_CALLS: test
fun test(a: Int, b: Int): Int {
var c = 0
b.times {
c += a
}
return c
}
fun box(): String {
assertEquals(6, test(2, 3))
assertEquals(6, test(3, 2))
assertEquals(20, test(4, 5))
return "OK"
}
@@ -0,0 +1,13 @@
package foo
val Int.abs: Int
get() = if (this >= 0) this else -this
fun test(xs: List<Int>): List<Int> =
xs.sortBy(comparator {(a, b) -> a.abs.compareTo(b.abs) })
fun box(): String {
assertEquals(listOf(1, -2, 3, -4), test(listOf(-2, 1, -4, 3)))
return "OK"
}
@@ -0,0 +1,24 @@
package foo
// CHECK_CONTAINS_NO_CALLS: test
fun test(a: Int, b: Int): Int {
var res = 0
with (a + b) {
val t = this
t.times {
res += t - b
}
}
return res
}
fun box(): String {
assertEquals(10, test(2, 3))
assertEquals(15, test(3, 2))
return "OK"
}
@@ -0,0 +1,19 @@
package foo
// CHECK_CONTAINS_NO_CALLS: test
fun test(x: Int, y: Int): Int =
with (x + x) {
val xx = this
with (y + y) {
xx + this
}
}
fun box(): String {
assertEquals(10, test(2, 3))
assertEquals(18, test(4, 5))
return "OK"
}
@@ -0,0 +1,19 @@
package foo
// CHECK_CONTAINS_NO_CALLS: test
var counter = 0
fun test(a: Int) {
a.times {
counter += 1
}
}
fun box(): String {
assertEquals(0, counter)
test(5)
assertEquals(5, counter)
return "OK"
}
@@ -0,0 +1,31 @@
package foo
// CHECK_CONTAINS_NO_CALLS: testImplicitThis
// CHECK_CONTAINS_NO_CALLS: testExplicitThis
class A(var value: Int)
fun testImplicitThis(a: A, newValue: Int) {
with (a) {
value = newValue
}
}
fun testExplicitThis(a: A, newValue: Int) {
with (a) {
this.value = newValue
}
}
fun box(): String {
val a = A(0)
assertEquals(0, a.value)
testImplicitThis(a, 10)
assertEquals(10, a.value)
testExplicitThis(a, 20)
assertEquals(20, a.value)
return "OK"
}