diff --git a/libraries/stdlib/wasm/build.gradle.kts b/libraries/stdlib/wasm/build.gradle.kts index bf5ce4f7cc2..3e317e084e2 100644 --- a/libraries/stdlib/wasm/build.gradle.kts +++ b/libraries/stdlib/wasm/build.gradle.kts @@ -53,10 +53,32 @@ val commonMainSources by task { into("$buildDir/commonMainSources") } +val commonTestSources by task { + val sources = listOf( + "libraries/stdlib/test/", + "libraries/stdlib/common/test/" + ) + + sources.forEach { path -> + from("$rootDir/$path") { + into(path.dropLastWhile { it != '/' }) + } + } + + into("$buildDir/commonTestSources") +} + kotlin { wasm { - nodejs() + nodejs { + testTask { + useMocha { + timeout = "10s" + } + } + } } + sourceSets { val wasmMain by getting { kotlin.srcDirs("builtins", "internal", "runtime", "src", "stubs") @@ -67,6 +89,20 @@ kotlin { val commonMain by getting { kotlin.srcDirs(files(commonMainSources.map { it.destinationDir })) } + + val commonTest by getting { + dependencies { + api(project(":kotlin-test:kotlin-test-wasm")) + } + kotlin.srcDir(files(commonTestSources.map { it.destinationDir })) + } + + val wasmTest by getting { + dependencies { + api(project(":kotlin-test:kotlin-test-wasm")) + } + kotlin.srcDir("$rootDir/libraries/stdlib/wasm/test/") + } } } @@ -90,6 +126,15 @@ tasks.named("compileKotlinWasm") { dependsOn(builtInsSources) } +val compileTestKotlinWasm by tasks.existing(KotlinCompile::class) { + val sources: FileCollection = kotlin.sourceSets["commonTest"].kotlin + doFirst { + // Note: common test sources are copied to the actual source directory by commonMainSources task, + // so can't do this at configuration time: + kotlinOptions.freeCompilerArgs += listOf("-Xcommon-sources=${sources.joinToString(",")}") + } +} + val runtimeElements by configurations.creating {} val apiElements by configurations.creating {} diff --git a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt index 39ca9154f50..f43be80ef30 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt @@ -1493,6 +1493,18 @@ public class Float private constructor(public val value: Float) : Number(), Comp */ @Suppress("DIVISION_BY_ZERO") public val NaN: Float = 0.0f / 0.0f + + /** + * The number of bytes used to represent an instance of Float in a binary form. + */ + @SinceKotlin("1.4") + public const val SIZE_BYTES: Int = 4 + + /** + * The number of bits used to represent an instance of Float in a binary form. + */ + @SinceKotlin("1.4") + public const val SIZE_BITS: Int = 32 } /** @@ -1801,6 +1813,18 @@ public class Double private constructor(public val value: Double) : Number(), Co */ @Suppress("DIVISION_BY_ZERO") public val NaN: Double = 0.0 / 0.0 + + /** + * The number of bytes used to represent an instance of Double in a binary form. + */ + @SinceKotlin("1.4") + public const val SIZE_BYTES: Int = 8 + + /** + * The number of bits used to represent an instance of Double in a binary form. + */ + @SinceKotlin("1.4") + public const val SIZE_BITS: Int = 64 } /** diff --git a/libraries/stdlib/wasm/test/collectionStubs.kt b/libraries/stdlib/wasm/test/collectionStubs.kt new file mode 100644 index 00000000000..a0480104e41 --- /dev/null +++ b/libraries/stdlib/wasm/test/collectionStubs.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2010-2021 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.collections.js + +public actual fun stringMapOf(vararg pairs: Pair): HashMap = hashMapOf(*pairs) +public actual fun linkedStringMapOf(vararg pairs: Pair): LinkedHashMap = linkedMapOf(*pairs) +public actual fun stringSetOf(vararg elements: String): HashSet = hashSetOf(*elements) +public actual fun linkedStringSetOf(vararg elements: String): LinkedHashSet = linkedSetOf(*elements) diff --git a/libraries/stdlib/wasm/test/stringEncoding.kt b/libraries/stdlib/wasm/test/stringEncoding.kt new file mode 100644 index 00000000000..ab5a16b37bd --- /dev/null +++ b/libraries/stdlib/wasm/test/stringEncoding.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2010-2021 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.text + +// TODO: Fix this once we implement kotlin.text +internal actual val surrogateCodePointDecoding: String = "�" + +internal actual val surrogateCharEncoding: ByteArray = byteArrayOf(0x3F) diff --git a/libraries/stdlib/wasm/test/testUtils.kt b/libraries/stdlib/wasm/test/testUtils.kt new file mode 100644 index 00000000000..36e5e241014 --- /dev/null +++ b/libraries/stdlib/wasm/test/testUtils.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2021 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 + +import kotlin.test.* + +public actual fun assertTypeEquals(expected: Any?, actual: Any?) { + TODO("Implement class references") + //assertEquals(expected?.let { it::class.js }, actual?.let { it::class.js }) +} + +@Suppress("NOTHING_TO_INLINE") +internal actual inline fun String.removeLeadingPlusOnJava6(): String = this + +internal actual inline fun testOnNonJvm6And7(f: () -> Unit) { + f() +} + + +public actual fun testOnJvm(action: () -> Unit) { } +public actual fun testOnJs(action: () -> Unit) { } + +// TODO: See KT-24975 +public actual val isFloat32RangeEnforced: Boolean = false + +// TODO: We need to implement this on wasm +actual val supportsSuppressedExceptions: Boolean get() = false + +// TODO: implement named group reference in replacement expression +public actual val supportsNamedCapturingGroup: Boolean get() = false