Files
kotlin-fork/plugins/atomicfu/atomicfu-compiler/testData/nativeBox/atomic_extensions/LambdaTest.kt
T
mvicsokolova 9ff0e0b046 [atomicfu-K/N] Tests for K/N atomicfu-compiler-plugin
* `nativeTest` task now allows to provide compiler plugins that may be enabled during test compilation
* test sets for JVM and K/N backends are equal

KT-60800 describes all the issues with native tests that were solved in this commit.

Co-authored-by: Dmitriy Dolovov <Dmitriy.Dolovov@jetbrains.com>

Merge-request: KT-MR-11401
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
2023-08-16 09:41:29 +00:00

53 lines
1.2 KiB
Kotlin
Vendored

import kotlinx.atomicfu.*
import kotlin.test.*
class LambdaTest {
private val a = atomic(0)
private val rs = atomic<String>("bbbb")
private inline fun <T> inlineLambda(
arg: T,
crossinline block: (T) -> Unit
) = block(arg)
fun loopInLambda1(to: Int) = inlineLambda(to) sc@ { arg ->
a.loop { value ->
a.compareAndSet(value, arg)
return@sc
}
}
fun loopInLambda2(to: Int) = inlineLambda(to) { arg1 ->
inlineLambda(arg1) sc@ { arg2 ->
a.loop { value ->
a.compareAndSet(value, arg2)
return@sc
}
}
}
fun loopInLambda2Ref(to: String) = inlineLambda(to) { arg1 ->
inlineLambda(arg1) sc@ { arg2 ->
rs.loop { value ->
rs.compareAndSet(value, arg2)
return@sc
}
}
}
fun test() {
loopInLambda1(34)
assertEquals(34, a.value)
loopInLambda1(77)
assertEquals(77, a.value)
loopInLambda2Ref("bbb")
assertEquals("bbb", rs.value)
}
}
@Test
fun box() {
val testClass = LambdaTest()
testClass.test()
}