From f849db54e18119f4d06235198a404eb54384a9b2 Mon Sep 17 00:00:00 2001 From: ssttkkl Date: Thu, 3 Oct 2024 17:12:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dentry=E7=9A=84wasmJs=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E7=BC=96=E8=AF=91=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mahjong-utils-entry/build.gradle.kts | 19 +- .../src/nonJsMain/kotlin/Main.kt | 1 - .../src/wasmMain/kotlin/Main.kt | 19 -- .../src/wasmTest/kotlin/TestEntry.kt | 242 ------------------ 4 files changed, 4 insertions(+), 277 deletions(-) delete mode 100644 mahjong-utils-entry/src/wasmMain/kotlin/Main.kt delete mode 100644 mahjong-utils-entry/src/wasmTest/kotlin/TestEntry.kt diff --git a/mahjong-utils-entry/build.gradle.kts b/mahjong-utils-entry/build.gradle.kts index f18ccf9..2c362b7 100644 --- a/mahjong-utils-entry/build.gradle.kts +++ b/mahjong-utils-entry/build.gradle.kts @@ -52,11 +52,6 @@ kotlin { ) } } - wasmWasi { - nodejs { - binaries.library() - } - } } if (enableNative) { @@ -98,23 +93,17 @@ kotlin { } } if (enableWasm) { - val wasmMain by creating { - dependsOn(commonMain) - } - val wasmTest by creating { - dependsOn(commonTest) - } val wasmJsMain by getting { - dependsOn(wasmMain) + dependsOn(nonJsMain) } val wasmJsTest by getting { - dependsOn(wasmTest) + dependsOn(nonJsTest) } val wasmWasiMain by getting { - dependsOn(wasmMain) + dependsOn(nonJsMain) } val wasmWasiTest by getting { - dependsOn(wasmTest) + dependsOn(nonJsTest) } } } diff --git a/mahjong-utils-entry/src/nonJsMain/kotlin/Main.kt b/mahjong-utils-entry/src/nonJsMain/kotlin/Main.kt index e69e32f..d00db06 100644 --- a/mahjong-utils-entry/src/nonJsMain/kotlin/Main.kt +++ b/mahjong-utils-entry/src/nonJsMain/kotlin/Main.kt @@ -9,7 +9,6 @@ import kotlin.js.JsExport internal val ENTRY = buildEntry(JsonParamsDecoder, JsonResultEncoder) - @JsExport fun call(name: String, rawParams: String): String { return ENTRY.call(name, rawParams) diff --git a/mahjong-utils-entry/src/wasmMain/kotlin/Main.kt b/mahjong-utils-entry/src/wasmMain/kotlin/Main.kt deleted file mode 100644 index 4c8b2c5..0000000 --- a/mahjong-utils-entry/src/wasmMain/kotlin/Main.kt +++ /dev/null @@ -1,19 +0,0 @@ -@file:OptIn(ExperimentalJsExport::class) - -import mahjongutils.entry.MethodExecutionException -import mahjongutils.entry.buildEntry -import mahjongutils.entry.coder.JsonParamsDecoder -import mahjongutils.entry.coder.JsonResultEncoder - -internal val ENTRY = buildEntry(JsonParamsDecoder, JsonResultEncoder) - -@JsExport -fun call(name: String, rawParams: String): String { - return ENTRY.call(name, rawParams) -} - -@JsExport -@Throws(MethodExecutionException::class) -fun callReceivingData(name: String, rawParams: String): String { - return ENTRY.callReceivingData(name, rawParams) -} diff --git a/mahjong-utils-entry/src/wasmTest/kotlin/TestEntry.kt b/mahjong-utils-entry/src/wasmTest/kotlin/TestEntry.kt deleted file mode 100644 index 9d53991..0000000 --- a/mahjong-utils-entry/src/wasmTest/kotlin/TestEntry.kt +++ /dev/null @@ -1,242 +0,0 @@ -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import mahjongutils.entry.Result -import mahjongutils.entry.models.HanHu -import mahjongutils.hanhu.ChildPoint -import mahjongutils.hanhu.ParentPoint -import mahjongutils.hanhu.getChildPointByHanHu -import mahjongutils.hanhu.getParentPointByHanHu -import mahjongutils.hora.Hora -import mahjongutils.hora.HoraArgs -import mahjongutils.hora.hora -import mahjongutils.models.Furo -import mahjongutils.models.Tile -import mahjongutils.models.Wind -import mahjongutils.shanten.ChitoiShantenResult -import mahjongutils.shanten.CommonShantenArgs -import mahjongutils.shanten.KokushiShantenResult -import mahjongutils.shanten.RegularShantenResult -import mahjongutils.shanten.UnionShantenResult -import mahjongutils.shanten.chitoiShanten -import mahjongutils.shanten.kokushiShanten -import mahjongutils.shanten.regularShanten -import mahjongutils.shanten.shanten -import mahjongutils.yaku.Yakus -import kotlin.test.Test -import kotlin.test.assertEquals - -class TestEntry { - @Test - fun testMethodNotFound() { - val rawResult = call("notExists", """{}""") - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(404, actualResult.code) - } - - @Test - fun testInvalidArgument() { - ENTRY.register("testInvalidArgument") { _ -> - throw IllegalArgumentException("Oops") - } - - val rawResult = call("testInvalidArgument", """{}""") - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(400, actualResult.code) - assertEquals("Oops", actualResult.msg) - } - - @Test - fun testInvalidArgument2() { - val rawResult = call("shanten", """{dfdafdfad}""") - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(400, actualResult.code) - } - - @Test - fun testInternalError() { - ENTRY.register("testInternalError") { _ -> - error("Oops") - } - - val rawResult = call("testInternalError", """{}""") - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(500, actualResult.code) - assertEquals("Oops", actualResult.msg) - } - - @Test - fun testShanten() { - val args = CommonShantenArgs( - Tile.parseTiles("11112345678s"), - listOf(Furo("999s")), - bestShantenOnly = true - ) - - val rawResult = call("shanten", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = shanten(args.tiles, args.furo, args.bestShantenOnly) - assertEquals(exceptResult, actualResult.data) - } - - @Test - fun testRegularShanten() { - val args = CommonShantenArgs( - Tile.parseTiles("11112345678s"), - listOf(Furo("999s")), - bestShantenOnly = true - ) - - val rawResult = call("regularShanten", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = - regularShanten(args.tiles, args.furo, args.bestShantenOnly) - assertEquals(exceptResult, actualResult.data) - } - - @Test - fun testChitoiShanten() { - val args = CommonShantenArgs( - Tile.parseTiles("11223344z556789p"), - bestShantenOnly = true - ) - - val rawResult = call("chitoiShanten", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = chitoiShanten(args.tiles, args.bestShantenOnly) - assertEquals(exceptResult, actualResult.data) - } - - @Test - fun testKokushiShanten() { - val args = CommonShantenArgs( - Tile.parseTiles("11223344556677z"), - bestShantenOnly = true - ) - - val rawResult = call("kokushiShanten", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = kokushiShanten(args.tiles, args.bestShantenOnly) - assertEquals(exceptResult, actualResult.data) - } - - @Test - fun testGetParentPointByHanHu() { - val args = HanHu(5, 30) - - val rawResult = call("getParentPointByHanHu", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = getParentPointByHanHu(args.han, args.hu) - assertEquals(exceptResult, actualResult.data) - } - - @Test - fun testGetChildPointByHanHu() { - val args = HanHu(5, 30) - - val rawResult = call("getChildPointByHanHu", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = getChildPointByHanHu(args.han, args.hu) - assertEquals(exceptResult, actualResult.data) - } - - @Test - fun testHora() { - val args = HoraArgs( - tiles = Tile.parseTiles("11123456s"), - furo = listOf(Furo("0110z"), Furo("789s")), - agari = Tile.get("1s"), - tsumo = true, - dora = 4, - selfWind = Wind.East, - roundWind = Wind.North, - extraYaku = setOf(Yakus.Rinshan) - ) - - val rawResult = call("hora", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = hora( - args.tiles!!, args.furo, args.agari, - args.tsumo, args.dora, args.selfWind, args.roundWind, args.extraYaku - ) - assertEquals(exceptResult, actualResult.data) - } - - @Test - fun testHora2() { - val shantenResult = shanten( - tiles = Tile.parseTiles("11123456s"), - furo = listOf(Furo("0110z"), Furo("789s")), - bestShantenOnly = true - ) - - val args = HoraArgs( - shantenResult = shantenResult, - agari = Tile.get("1s"), - tsumo = true, - dora = 4, - selfWind = Wind.East, - roundWind = Wind.North, - extraYaku = setOf(Yakus.Rinshan) - ) - - val rawResult = call("hora", Json.encodeToString(args)) - print("rawResult: ") - println(rawResult) - - val actualResult: Result = Json.decodeFromString(rawResult) - assertEquals(200, actualResult.code) - - val exceptResult = hora( - args.shantenResult!!, args.agari, - args.tsumo, args.dora, args.selfWind, args.roundWind, args.extraYaku - ) - assertEquals(exceptResult, actualResult.data) - } -} \ No newline at end of file