JS: move inline test to box tests
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
public var LOG: String = ""
|
||||
|
||||
inline
|
||||
public fun log(s: String): String {
|
||||
LOG += s
|
||||
return LOG
|
||||
}
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal fun test(s: String): String = log(s + ";")
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("a;", test("a"))
|
||||
assertEquals("a;b;", test("b"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R =
|
||||
fn(x)
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal fun multiplyBy2(x: Int): Int = x * 2
|
||||
|
||||
internal fun test(x: Int): Int = apply(x, ::multiplyBy2)
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(6, test(3))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun sum(x: Int, y: Int): Int =
|
||||
x + y
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal 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,26 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun <T, R> apply(x: T, fn: T.()->R): R =
|
||||
x.fn()
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal class A(val n: Int)
|
||||
|
||||
internal fun test(a: A, m: Int): Int = apply(a) { n * m }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(6, test(A(2), 3))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package lib
|
||||
|
||||
var global = ""
|
||||
|
||||
inline fun baz(x: () -> Int) = A(1).bar(x())
|
||||
|
||||
class A(val y: Int) {
|
||||
fun bar(x: Int) = x + y
|
||||
}
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
package foo
|
||||
|
||||
import lib.*
|
||||
|
||||
fun qqq(): Int {
|
||||
global += "qqq;"
|
||||
return 23
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(24, baz {
|
||||
global += "before;"
|
||||
val result = qqq()
|
||||
global += "after;"
|
||||
result
|
||||
})
|
||||
assertEquals("before;qqq;after;", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package lib
|
||||
|
||||
var global = ""
|
||||
|
||||
inline fun baz(x: () -> Int) = ((A(1).B(x()) as Any) as A.B).bar()
|
||||
|
||||
class A(val y: Int) {
|
||||
inner class B(val x: Int) {
|
||||
fun bar() = x + y
|
||||
}
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
package foo
|
||||
|
||||
import lib.*
|
||||
|
||||
fun qqq(): Int {
|
||||
global += "qqq;"
|
||||
return 23
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(24, baz {
|
||||
global += "before;"
|
||||
val result = qqq()
|
||||
global += "after;"
|
||||
result
|
||||
})
|
||||
assertEquals("before;qqq;after;", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R =
|
||||
fn(x)
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal fun test(x: Int): Int = apply(x) { it * 2 }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(6, test(3))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun <T, R> apply(x: T, crossinline fn: (T)->R): R {
|
||||
val result = object {
|
||||
val x = fn(x)
|
||||
}
|
||||
|
||||
return result.x
|
||||
}
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
internal fun test(x: Int): Int = apply(x) { it * 2 }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(6, test(3))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R =
|
||||
fn(x)
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal fun test(x: Int, y: Int): Int = apply(x) { it + y }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(3, test(1, 2))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun <T, R> apply(x: T, fn: (T)->R): R {
|
||||
val y = fn(x)
|
||||
return y
|
||||
}
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal 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,25 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
public class A(public val x: Int) {
|
||||
inline
|
||||
public fun plus(y: Int): Int = x + y
|
||||
}
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal fun test(a: A, y: Int): Int = a.plus(y)
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(5, test(A(2), 3))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package foo
|
||||
|
||||
inline fun bar(x: Int = 0) = x + 10
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: bar
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(10, bar())
|
||||
assertEquals(11, bar(1))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
package utils
|
||||
|
||||
inline
|
||||
public fun sum(x: Int, y: Int): Int =
|
||||
x + y
|
||||
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import utils.*
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user