JS: move inline test to box tests
This commit is contained in:
@@ -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) {
|
||||
companion 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"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=test function=even
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=test function=filter_azvtw4$
|
||||
|
||||
internal fun even(x: Int) = x % 2 == 0
|
||||
|
||||
internal fun test(a: List<Int>) = a.filter(::even)
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf(2, 4), test(listOf(1, 2, 3, 4)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
internal fun test(a: Int, b: Int): Int {
|
||||
var c = 0
|
||||
|
||||
repeat(b) {
|
||||
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,15 @@
|
||||
package foo
|
||||
|
||||
import kotlin.comparisons.*
|
||||
|
||||
val Int.abs: Int
|
||||
get() = if (this >= 0) this else -this
|
||||
|
||||
fun test(xs: List<Int>): List<Int> =
|
||||
xs.sortedWith(compareBy { it.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
|
||||
|
||||
internal fun test(a: Int, b: Int): Int {
|
||||
var res = 0
|
||||
|
||||
with (a + b) {
|
||||
val t = this
|
||||
|
||||
repeat(t) {
|
||||
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
|
||||
|
||||
internal 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
|
||||
|
||||
internal var counter = 0
|
||||
|
||||
internal fun test(a: Int) {
|
||||
repeat(a) {
|
||||
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
|
||||
|
||||
internal class A(var value: Int)
|
||||
|
||||
internal fun testImplicitThis(a: A, newValue: Int) {
|
||||
with (a) {
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
|
||||
internal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user