diff --git a/build.gradle.kts b/build.gradle.kts index b2f1ffc..f68bb47 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -146,7 +146,7 @@ kotlin { commonTest { dependencies { implementation(libs.kotlin.test) - implementation(libs.kotest.assertions.core) + implementation(libs.xemantic.kotlin.test) implementation(libs.kotest.assertions.json) implementation(libs.kotlinx.datetime) implementation(libs.bignum) @@ -201,10 +201,9 @@ tasks.withType { } powerAssert { - // power assert temporarily switched off for kotest, since it stopped working with kotlin 2.1 -// functions = listOf( -// "io.kotest.matchers.shouldBe" -// ) + functions = listOf( + "com.xemantic.kotlin.test.have" + ) } // https://kotlinlang.org/docs/dokka-migration.html#adjust-configuration-options diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c0713ff..9ac816b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,6 +5,9 @@ javaTarget = "17" kotlin = "2.1.0" kotlinxSerialization = "1.7.3" kotlinxDatetime = "0.6.1" + +xemanticKotlinTest = "0.1.1" + kotest = "6.0.0.M1" bignum = "0.3.10" @@ -20,7 +23,8 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotl kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" } kotlinx-datetime = { module="org.jetbrains.kotlinx:kotlinx-datetime", version.ref="kotlinxDatetime" } -kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } +xemantic-kotlin-test = { module="com.xemantic.kotlin:xemantic-kotlin-test", version.ref="xemanticKotlinTest" } + kotest-assertions-json = { module = "io.kotest:kotest-assertions-json", version.ref = "kotest" } bignum = { module = "com.ionspin.kotlin:bignum", version.ref = "bignum" } diff --git a/src/commonTest/kotlin/JsonSchemaTest.kt b/src/commonTest/kotlin/JsonSchemaTest.kt index 41a8415..6ef2d25 100644 --- a/src/commonTest/kotlin/JsonSchemaTest.kt +++ b/src/commonTest/kotlin/JsonSchemaTest.kt @@ -17,8 +17,10 @@ package com.xemantic.ai.tool.schema import io.kotest.assertions.json.shouldEqualJson -import io.kotest.assertions.throwables.shouldThrowWithMessage +import com.xemantic.kotlin.test.should +import com.xemantic.kotlin.test.have import kotlin.test.Test +import kotlin.test.assertFailsWith class JsonSchemaTest { @@ -33,7 +35,7 @@ class JsonSchemaTest { ) required = listOf("name") additionalProperties = false - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "object", "title": "Person", @@ -68,7 +70,7 @@ class JsonSchemaTest { ) } ) - }.toString() shouldEqualJson $$""" + }.toString() shouldEqualJson /* language=json */ $$""" { "type": "object", "title": "Person", @@ -99,7 +101,7 @@ class JsonSchemaTest { @Test fun `should create empty ObjectSchema`() { - ObjectSchema {}.toString() shouldEqualJson """{"type": "object"}""" + ObjectSchema {}.toString() shouldEqualJson /* language=json */ """{"type": "object"}""" } @Test @@ -110,7 +112,7 @@ class JsonSchemaTest { minLength = 3 maxLength = 20 pattern = "^[a-zA-Z0-9_]+$" - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "string", "title": "Username", @@ -130,7 +132,7 @@ class JsonSchemaTest { minLength = 3 maxLength = 100 format(StringFormat.EMAIL) - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "string", "title": "Email", @@ -147,7 +149,7 @@ class JsonSchemaTest { StringSchema { title = "Color" enum = listOf("red", "green", "blue") - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "string", "title": "Color", @@ -163,20 +165,20 @@ class JsonSchemaTest { description = "User's avatar image" contentEncoding = ContentEncoding.BASE64 contentMediaType = "image/png" - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "string", "title": "Image", "description": "User's avatar image", "contentEncoding": "base64", "contentMediaType": "image/png" - } + } """ } @Test fun `should create empty StringSchema`() { - StringSchema {}.toString() shouldEqualJson """{"type": "string"}""" + StringSchema {}.toString() shouldEqualJson /* language=json */ """{"type": "string"}""" } @Test @@ -188,7 +190,7 @@ class JsonSchemaTest { minItems = 1 maxItems = 10 uniqueItems = true - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "array", "title": "Numbers", @@ -213,7 +215,7 @@ class JsonSchemaTest { "name" to StringSchema {} ) } - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "array", "title": "Users", @@ -240,7 +242,7 @@ class JsonSchemaTest { minimum = 0.0 maximum = 1000.0 multipleOf = 0.01 - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "number", "title": "Price", @@ -259,7 +261,7 @@ class JsonSchemaTest { description = "A price value" exclusiveMinimum = 0.0 exclusiveMaximum = 1000.0 - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "number", "title": "Price", @@ -272,7 +274,7 @@ class JsonSchemaTest { @Test fun `should create empty NumberSchema`() { - NumberSchema {}.toString() shouldEqualJson """{"type": "number"}""" + NumberSchema {}.toString() shouldEqualJson /* language=json */ """{"type": "number"}""" } @Test @@ -283,7 +285,7 @@ class JsonSchemaTest { minimum = 0 maximum = 120 multipleOf = 1 - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "integer", "title": "Age", @@ -302,7 +304,7 @@ class JsonSchemaTest { description = "A person's age" exclusiveMinimum = 0 exclusiveMaximum = 120 - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "integer", "title": "Age", @@ -315,7 +317,7 @@ class JsonSchemaTest { @Test fun `should create empty IntegerSchema`() { - IntegerSchema {}.toString() shouldEqualJson """{"type": "integer"}""" + IntegerSchema {}.toString() shouldEqualJson /* language=json */ """{"type": "integer"}""" } @Test @@ -323,7 +325,7 @@ class JsonSchemaTest { BooleanSchema { title = "Is Active" description = "Whether the user is active" - }.toString() shouldEqualJson """ + }.toString() shouldEqualJson /* language=json */ """ { "type": "boolean", "title": "Is Active", @@ -334,12 +336,12 @@ class JsonSchemaTest { @Test fun `should create empty BooleanSchema`() { - BooleanSchema {}.toString() shouldEqualJson """{"type": "boolean"}""" + BooleanSchema {}.toString() shouldEqualJson /* language=json */ """{"type": "boolean"}""" } @Test fun `should create JsonSchemaRef`() { - JsonSchema.Ref("#/definitions/address").toString() shouldEqualJson $$""" + JsonSchema.Ref("#/definitions/address").toString() shouldEqualJson /* language=json */ $$""" { "$ref": "#/definitions/address" } @@ -348,10 +350,10 @@ class JsonSchemaTest { @Test fun `should throw Exception for invalid JSON Pointer passed to JsonSchemaRef`() { - shouldThrowWithMessage( - "The 'ref' must start with '#/'" - ) { + assertFailsWith { JsonSchema.Ref("invalid_ref") + } should { + have(message == "The 'ref' must start with '#/'") } } diff --git a/src/commonTest/kotlin/generator/JsonSchemaGeneratorTest.kt b/src/commonTest/kotlin/generator/JsonSchemaGeneratorTest.kt index f8e83c3..36b8993 100644 --- a/src/commonTest/kotlin/generator/JsonSchemaGeneratorTest.kt +++ b/src/commonTest/kotlin/generator/JsonSchemaGeneratorTest.kt @@ -76,7 +76,7 @@ class JsonSchemaGeneratorTest { @Test fun `generate JSON Schema for Address`() { val schema = jsonSchemaOf
() - testJson.encodeToString(schema) shouldEqualJson """ + testJson.encodeToString(schema) shouldEqualJson /* language=json */ """ { "type": "object", "title": "The full address", @@ -181,7 +181,7 @@ class JsonSchemaGeneratorTest { val schemaJson = testJson.encodeToString(schema) // then - schemaJson shouldEqualJson $$""" + schemaJson shouldEqualJson /* language=json */ $$""" { "type": "object", "description": "Personal data", @@ -346,7 +346,7 @@ class JsonSchemaGeneratorTest { @Test fun `should prioritize title and description set on property over the one set for the whole class`() { val schema = jsonSchemaOf() - testJson.encodeToString(schema) shouldEqualJson $$""" + testJson.encodeToString(schema) shouldEqualJson /* language=json */ $$""" { "type": "object", "description": "A container of monetary amounts", @@ -377,7 +377,7 @@ class JsonSchemaGeneratorTest { val schema = jsonSchemaOf( suppressDescription = true ) - testJson.encodeToString(schema) shouldEqualJson $$""" + testJson.encodeToString(schema) shouldEqualJson /* language=json */ $$""" { "type": "object", "properties": { @@ -416,7 +416,7 @@ class JsonSchemaGeneratorTest { val schema = jsonSchemaOf( outputAdditionalPropertiesFalse = true ) - testJson.encodeToString(schema) shouldEqualJson $$""" + testJson.encodeToString(schema) shouldEqualJson /* language=json */ $$""" { "type": "object", "properties": { diff --git a/src/commonTest/kotlin/serialization/JsonSchemaSerializerTest.kt b/src/commonTest/kotlin/serialization/JsonSchemaSerializerTest.kt index 244a36d..6f9b1e9 100644 --- a/src/commonTest/kotlin/serialization/JsonSchemaSerializerTest.kt +++ b/src/commonTest/kotlin/serialization/JsonSchemaSerializerTest.kt @@ -18,27 +18,31 @@ package com.xemantic.ai.tool.schema.serialization import com.xemantic.ai.tool.schema.JsonSchema import com.xemantic.ai.tool.schema.test.testJson +import com.xemantic.kotlin.test.be +import com.xemantic.kotlin.test.have +import com.xemantic.kotlin.test.should import io.kotest.assertions.json.shouldEqualJson -import io.kotest.matchers.shouldBe -import io.kotest.matchers.types.instanceOf import kotlin.test.Test class JsonSchemaSerializerTest { @Test fun `should decode JsonSchema reference`() { + /* language=json */ val json = $$""" { "$ref": "#/definitions/foo" } - """.trimIndent() - val ref = testJson.decodeFromString(json) - ref shouldBe instanceOf() - (ref as JsonSchema.Ref).ref shouldBe "#/definitions/foo" + """ + testJson.decodeFromString(json) should { + be() + have(ref == "#/definitions/foo") + } } @Test fun `decode JSON Schema from JSON`() { + /* language=json */ val json = $$""" { "type": "object", @@ -181,7 +185,11 @@ class JsonSchemaSerializerTest { } } """ + + // when val schema = testJson.decodeFromString(json) + + // then schema.toString() shouldEqualJson json } diff --git a/src/jvmTest/kotlin/serialization/JavaBigDecimalToSchemaTest.kt b/src/jvmTest/kotlin/serialization/JavaBigDecimalToSchemaTest.kt index d2c14e5..ec903b2 100644 --- a/src/jvmTest/kotlin/serialization/JavaBigDecimalToSchemaTest.kt +++ b/src/jvmTest/kotlin/serialization/JavaBigDecimalToSchemaTest.kt @@ -45,7 +45,7 @@ class JavaBigDecimalToSchemaTest { @Test fun `should represent Java BigDecimal as String with pattern and description JSON Schema`() { val schema = jsonSchemaOf() - testJson.encodeToString(schema) shouldEqualJson $$""" + testJson.encodeToString(schema) shouldEqualJson /* language=json */ $$""" { "type": "object", "properties": {