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
@@ -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