Skip to content

Commit

Permalink
redundant per-platform Money code removed
Browse files Browse the repository at this point in the history
  • Loading branch information
morisil committed Dec 5, 2024
1 parent 7311b62 commit 6387706
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 148 deletions.
26 changes: 24 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ repositories {

kotlin {

applyDefaultHierarchyTemplate()

explicitApi()

compilerOptions {
Expand Down Expand Up @@ -151,6 +153,26 @@ kotlin {
}
}

val nonJvmTest by creating {
dependsOn(commonTest.get())
}

nativeTest {
dependsOn(nonJvmTest)
}

jsTest {
dependsOn(nonJvmTest)
}

wasmJsTest {
dependsOn(nonJvmTest)
}

wasmWasiTest {
dependsOn(nonJvmTest)
}

}

}
Expand Down Expand Up @@ -188,7 +210,7 @@ powerAssert {
// https://kotlinlang.org/docs/dokka-migration.html#adjust-configuration-options
dokka {
pluginsConfiguration.html {
footerMessage.set("© Xemantic 2024")
footerMessage.set("(c) 2024 Xemantic")
}
}

Expand All @@ -215,7 +237,7 @@ publishing {
artifact(javadocJar)
pom {
name = "xemantic-ai-tool-schema"
description = "A Kotlin multiplatform AI/LLM tool use (function calling) JSON Schema generator"
description = "Kotlin multiplatform AI/LLM tool use (function calling) JSON Schema generator"
url = "https://github.com/$githubAccount/${rootProject.name}"
inceptionYear = "2024"
organization {
Expand Down
14 changes: 7 additions & 7 deletions src/commonTest/kotlin/test/Money.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ interface Money {

expect fun Money(amount: String): Money

// It's a hack to autogenerate a serializer which will retain annotations of serialized class
@OptIn(ExperimentalSerializationApi::class)
@Serializer(forClass = Money::class)
private object AutoGeneratedMoneySerializer

object MoneySerializer : KSerializer<Money> {

// It's a hack to autogenerate a serializer which will retain annotations of serialized class
@OptIn(ExperimentalSerializationApi::class)
@Serializer(forClass = Money::class)
private object AutoSerializer

@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
override val descriptor = buildSerialDescriptor(
serialName = AutoGeneratedMoneySerializer.descriptor.serialName,
serialName = AutoSerializer.descriptor.serialName,
kind = PrimitiveKind.STRING
) {
annotations = AutoGeneratedMoneySerializer.descriptor.annotations
annotations = AutoSerializer.descriptor.annotations
}

override fun serialize(encoder: Encoder, value: Money) {
Expand Down
1 change: 1 addition & 0 deletions src/jvmTest/kotlin/test/JvmMoney.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class JvmMoney(

}

@Suppress("TestFunctionName")
actual fun Money(
amount: String
): Money = JvmMoney(BigDecimal(amount))
42 changes: 0 additions & 42 deletions src/nativeTest/kotlin/NativeMoney.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ package com.xemantic.ai.tool.schema.test
import com.ionspin.kotlin.bignum.decimal.BigDecimal

/**
* The `js` flavor of test money.
* The `nonJvm` flavor of test money.
*/
class JsMoney(
class NonJvmMoney(
private val value: BigDecimal
) : Money {

override fun plus(
amount: Money
) = JsMoney(value + (amount as JsMoney).value)
) = NonJvmMoney(value + (amount as NonJvmMoney).value)

override fun compareTo(
other: Money
) = value.compareTo(
(other as JsMoney).value
(other as NonJvmMoney).value
)

override fun toString(): String {
Expand All @@ -41,6 +41,7 @@ class JsMoney(

}

@Suppress("TestFunctionName")
actual fun Money(
amount: String
): Money = JsMoney(BigDecimal.parseString(amount))
): Money = NonJvmMoney(BigDecimal.parseString(amount))
46 changes: 0 additions & 46 deletions src/wasmJsTest/kotlin/WasmJsMoney.kt

This file was deleted.

46 changes: 0 additions & 46 deletions src/wasmWasiTest/kotlin/WasmWasiJsMoney.kt

This file was deleted.

0 comments on commit 6387706

Please sign in to comment.