diff --git a/dsl-template/src/commonMain/kotlin/aggregation/Value.kt b/dsl-template/src/commonMain/kotlin/aggregation/Value.kt index 840be22b..6bc84f1e 100644 --- a/dsl-template/src/commonMain/kotlin/aggregation/Value.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/Value.kt @@ -146,6 +146,7 @@ abstract class AbstractValue private constructor( */ @OptIn(LowLevelApi::class) fun toString(simplified: Boolean): String { + // Create an array of a single element because we can't write a value by itself, it needs to be in some kind of container val document = context.buildArray { if (simplified) writeTo(this) @@ -154,6 +155,10 @@ abstract class AbstractValue private constructor( } return document.toString() + // Remove the fake array + .trim() + .removeSurrounding("[", "]") + .trim() } final override fun toString(): String = diff --git a/dsl/src/commonMain/kotlin/aggregation/Value.kt b/dsl/src/commonMain/kotlin/aggregation/Value.kt index d533da74..03866da7 100644 --- a/dsl/src/commonMain/kotlin/aggregation/Value.kt +++ b/dsl/src/commonMain/kotlin/aggregation/Value.kt @@ -149,6 +149,7 @@ abstract class AbstractValue private constructor( */ @OptIn(LowLevelApi::class) fun toString(simplified: Boolean): String { + // Create an array of a single element because we can't write a value by itself, it needs to be in some kind of container val document = context.buildArray { if (simplified) writeTo(this) @@ -157,6 +158,10 @@ abstract class AbstractValue private constructor( } return document.toString() + // Remove the fake array + .trim() + .removeSurrounding("[", "]") + .trim() } final override fun toString(): String = diff --git a/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt b/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt index 400ef0c1..0313a025 100644 --- a/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/ValueTest.kt @@ -50,9 +50,7 @@ val ValueTest by multiContextSuite { value { of(User::name) } shouldBeBson """ - [ - "${dollar}name" - ] + "${dollar}name" """.trimIndent() } @@ -60,9 +58,7 @@ val ValueTest by multiContextSuite { value { of(User::profile / Profile::age) } shouldBeBson """ - [ - "${dollar}profile.age" - ] + "${dollar}profile.age" """.trimIndent() } } @@ -72,11 +68,9 @@ val ValueTest by multiContextSuite { value { of(5) } shouldBeBson $$""" - [ - { - "$literal": 5 - } - ] + { + "$literal": 5 + } """.trimIndent() } @@ -84,11 +78,9 @@ val ValueTest by multiContextSuite { value { of(null) } shouldBeBson $$""" - [ - { - "$literal": null - } - ] + { + "$literal": null + } """.trimIndent() } } @@ -97,16 +89,14 @@ val ValueTest by multiContextSuite { value { 5 eq User::profile / Profile::age } shouldBeBson $$""" - [ - { - "$eq": [ - { - "$literal": 5 - }, - "$profile.age" - ] - } - ] + { + "$eq": [ + { + "$literal": 5 + }, + "$profile.age" + ] + } """.trimIndent() } }