JS test: added multi-module inline tests
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package utils
|
||||
|
||||
public var LOG: String = ""
|
||||
|
||||
inline
|
||||
public fun log(s: String): String {
|
||||
LOG += s
|
||||
return LOG
|
||||
}
|
||||
+12
@@ -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"
|
||||
}
|
||||
+10
@@ -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
|
||||
}
|
||||
+9
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user