Files
kotlin-fork/plugins/atomicfu/atomicfu-compiler/testData/box/LockTest.kt
T
mvicsokolova 93561a1a55 kotlinx.atomicfu compiler plugin for JS_IR backend (#4581)
* kotlinx.atomicfu compiler plugin for JS_IR

Support transformations of atomic operations introduced by the kotlinx.atomicfu library for the JS_IR backend. Compiler plugin is applied externally by the kotlinx.atomicfu gradle plugin.

* Apply compiler plugin for JS platform only

* New plugin test structure

* testGroupOutputDirPrefix changed
2021-12-01 22:33:13 +03:00

29 lines
804 B
Kotlin
Vendored

import kotlinx.atomicfu.*
import kotlin.test.*
class LockTest {
private val inProgressLock = atomic(false)
fun testLock() {
var result = ""
if (inProgressLock.tryAcquire()) {
result = "OK"
}
assertEquals("OK", result)
}
}
// This function will be removed by transformer
@Suppress("NOTHING_TO_INLINE")
private inline fun AtomicBoolean.tryAcquire(): Boolean = compareAndSet(false, true)
// This function is here to test if the Kotlin metadata still consistent after transform
// It is used in ReflectionTest, DO NOT REMOVE
@Suppress("UNUSED_PARAMETER")
fun <AA, BB : Number> String.reflectionTest(mapParam: Map<in AA, BB>): List<BB> = error("no impl")
fun box(): String {
val testClass = LockTest()
testClass.testLock()
return "OK"
}