[Wasm] Add box and stdlib tests in wasi mode
This commit is contained in:
committed by
Zalim Bashorov
parent
f42d0b1ed4
commit
983991d46c
@@ -18,7 +18,7 @@ configureWasmStdLib(
|
||||
wasmTargetParameter = "wasm-js",
|
||||
wasmTargetAttribute = KotlinWasmTargetAttribute.js,
|
||||
targetDependentSources = targetDependentSources,
|
||||
targetDependentTestSources = listOf("$rootDir/libraries/stdlib/wasm/testJs/"),
|
||||
targetDependentTestSources = listOf("$rootDir/libraries/stdlib/wasm/js/test/"),
|
||||
kotlinTestDependencyName = ":kotlin-test:kotlin-test-wasm-js"
|
||||
) { extensionBody ->
|
||||
kotlin(extensionBody)
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test.js
|
||||
|
||||
import kotlin.js.*
|
||||
import kotlin.test.*
|
||||
|
||||
internal fun jsAsyncFoo(): Promise<JsAny?> =
|
||||
js("(async () => 'foo')()")
|
||||
|
||||
internal fun jsFoo(): JsAny =
|
||||
js("'foo'")
|
||||
|
||||
var state: JsAny? = null
|
||||
|
||||
class MyThrowable : Throwable()
|
||||
|
||||
class AsyncTest {
|
||||
@Test
|
||||
fun test1(): Promise<JsAny?> {
|
||||
var thenExecuted = false
|
||||
val p = jsAsyncFoo().then { value ->
|
||||
state = value
|
||||
thenExecuted = true
|
||||
null
|
||||
}
|
||||
assertFalse(thenExecuted)
|
||||
return p
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test2(): Promise<JsAny?> {
|
||||
assertEquals(state, jsFoo())
|
||||
var thenExecuted = false
|
||||
val p = jsAsyncFoo().then {
|
||||
assertEquals(state, jsFoo())
|
||||
thenExecuted = true
|
||||
null
|
||||
}.then {
|
||||
assertEquals(state, jsFoo())
|
||||
thenExecuted = true
|
||||
null
|
||||
}
|
||||
assertFalse(thenExecuted)
|
||||
return p
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJsValueToThrowableOrNull1(): Promise<JsAny?> {
|
||||
val p = jsAsyncFoo().then {
|
||||
throw MyThrowable()
|
||||
}.catch { e ->
|
||||
assert(e.toThrowableOrNull() is MyThrowable)
|
||||
null
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJsValueToThrowableOrNull2() {
|
||||
val e = MyThrowable()
|
||||
assertEquals((e.toJsReference()).toThrowableOrNull(), e)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
public actual val TestPlatform.Companion.current: TestPlatform get() = TestPlatform.WasmJs
|
||||
@@ -0,0 +1,18 @@
|
||||
package test.wasm.unsafe
|
||||
|
||||
import kotlin.wasm.unsafe.*
|
||||
import kotlin.test.*
|
||||
|
||||
private fun jsConcatStrings(a: String, b: String): String =
|
||||
js("a + b")
|
||||
|
||||
@OptIn(UnsafeWasmMemoryApi::class)
|
||||
class MemoryAllocationJsTest {
|
||||
@Test
|
||||
fun testJsIntropInsideAllocations() {
|
||||
withScopedMemoryAllocator { allocator ->
|
||||
assertEquals(jsConcatStrings("str1", "str2"), "str1str2")
|
||||
allocator.allocate(10)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user