From 82019ddf5e15fa7fd778a868287fb3e906ba6273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sun, 15 Sep 2024 11:06:28 +0200 Subject: [PATCH] test(dsl): Create test helpers --- dsl/src/commonTest/kotlin/Marker.kt | 17 +++ .../kotlin/expr/ExpressionTestUtils.kt | 30 ++++ dsl/src/jsTest/kotlin/Marker.kt | 17 +++ .../kotlin/expr/ExpressionTestUtils.js.kt | 21 +++ dsl/src/jvmTest/kotlin/Marker.kt | 17 +++ .../kotlin/expr/ExpressionTestUtils.jvm.kt | 131 ++++++++++++++++++ .../test/kotlin/expr/ExpressionTestUtils.kt | 74 ---------- 7 files changed, 233 insertions(+), 74 deletions(-) create mode 100644 dsl/src/commonTest/kotlin/Marker.kt create mode 100644 dsl/src/commonTest/kotlin/expr/ExpressionTestUtils.kt create mode 100644 dsl/src/jsTest/kotlin/Marker.kt create mode 100644 dsl/src/jsTest/kotlin/expr/ExpressionTestUtils.js.kt create mode 100644 dsl/src/jvmTest/kotlin/Marker.kt create mode 100644 dsl/src/jvmTest/kotlin/expr/ExpressionTestUtils.jvm.kt delete mode 100644 prototype/dsl/src/test/kotlin/expr/ExpressionTestUtils.kt diff --git a/dsl/src/commonTest/kotlin/Marker.kt b/dsl/src/commonTest/kotlin/Marker.kt new file mode 100644 index 00000000..78149a84 --- /dev/null +++ b/dsl/src/commonTest/kotlin/Marker.kt @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl diff --git a/dsl/src/commonTest/kotlin/expr/ExpressionTestUtils.kt b/dsl/src/commonTest/kotlin/expr/ExpressionTestUtils.kt new file mode 100644 index 00000000..5e750016 --- /dev/null +++ b/dsl/src/commonTest/kotlin/expr/ExpressionTestUtils.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl.expr + +import io.kotest.matchers.shouldBe +import opensavvy.ktmongo.bson.BsonContext + +expect fun testContext(): BsonContext + +infix fun String.shouldBeBson(expected: String) { + this shouldBe expected + .replace("\n", "") + .replace("\t", "") + .replace(",", ", ") + .replace(" ", " ") +} diff --git a/dsl/src/jsTest/kotlin/Marker.kt b/dsl/src/jsTest/kotlin/Marker.kt new file mode 100644 index 00000000..78149a84 --- /dev/null +++ b/dsl/src/jsTest/kotlin/Marker.kt @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl diff --git a/dsl/src/jsTest/kotlin/expr/ExpressionTestUtils.js.kt b/dsl/src/jsTest/kotlin/expr/ExpressionTestUtils.js.kt new file mode 100644 index 00000000..f44f5206 --- /dev/null +++ b/dsl/src/jsTest/kotlin/expr/ExpressionTestUtils.js.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl.expr + +import opensavvy.ktmongo.bson.BsonContext + +actual fun testContext(): BsonContext = BsonContext() diff --git a/dsl/src/jvmTest/kotlin/Marker.kt b/dsl/src/jvmTest/kotlin/Marker.kt new file mode 100644 index 00000000..78149a84 --- /dev/null +++ b/dsl/src/jvmTest/kotlin/Marker.kt @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl diff --git a/dsl/src/jvmTest/kotlin/expr/ExpressionTestUtils.jvm.kt b/dsl/src/jvmTest/kotlin/expr/ExpressionTestUtils.jvm.kt new file mode 100644 index 00000000..d5d95821 --- /dev/null +++ b/dsl/src/jvmTest/kotlin/expr/ExpressionTestUtils.jvm.kt @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2024, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.dsl.expr + +import opensavvy.ktmongo.bson.BsonContext +import org.bson.codecs.AtomicBooleanCodec +import org.bson.codecs.AtomicIntegerCodec +import org.bson.codecs.AtomicLongCodec +import org.bson.codecs.BigDecimalCodec +import org.bson.codecs.BinaryCodec +import org.bson.codecs.BooleanCodec +import org.bson.codecs.BsonArrayCodec +import org.bson.codecs.BsonBinaryCodec +import org.bson.codecs.BsonBooleanCodec +import org.bson.codecs.BsonDBPointerCodec +import org.bson.codecs.BsonDateTimeCodec +import org.bson.codecs.BsonDecimal128Codec +import org.bson.codecs.BsonDocumentCodec +import org.bson.codecs.BsonDoubleCodec +import org.bson.codecs.BsonInt32Codec +import org.bson.codecs.BsonInt64Codec +import org.bson.codecs.BsonJavaScriptCodec +import org.bson.codecs.BsonMaxKeyCodec +import org.bson.codecs.BsonMinKeyCodec +import org.bson.codecs.BsonNullCodec +import org.bson.codecs.BsonObjectIdCodec +import org.bson.codecs.BsonRegularExpressionCodec +import org.bson.codecs.BsonStringCodec +import org.bson.codecs.BsonSymbolCodec +import org.bson.codecs.BsonTimestampCodec +import org.bson.codecs.BsonUndefinedCodec +import org.bson.codecs.BsonValueCodec +import org.bson.codecs.ByteArrayCodec +import org.bson.codecs.ByteCodec +import org.bson.codecs.CharacterCodec +import org.bson.codecs.CodeCodec +import org.bson.codecs.DateCodec +import org.bson.codecs.Decimal128Codec +import org.bson.codecs.DocumentCodec +import org.bson.codecs.DoubleCodec +import org.bson.codecs.FloatCodec +import org.bson.codecs.IntegerCodec +import org.bson.codecs.JsonObjectCodec +import org.bson.codecs.LongCodec +import org.bson.codecs.MaxKeyCodec +import org.bson.codecs.MinKeyCodec +import org.bson.codecs.ObjectIdCodec +import org.bson.codecs.OverridableUuidRepresentationUuidCodec +import org.bson.codecs.PatternCodec +import org.bson.codecs.RawBsonDocumentCodec +import org.bson.codecs.ShortCodec +import org.bson.codecs.StringCodec +import org.bson.codecs.SymbolCodec +import org.bson.codecs.UuidCodec +import org.bson.codecs.configuration.CodecRegistries +import org.bson.codecs.jsr310.InstantCodec +import org.bson.codecs.jsr310.LocalDateCodec +import org.bson.codecs.jsr310.LocalDateTimeCodec +import org.bson.codecs.jsr310.LocalTimeCodec + +actual fun testContext(): BsonContext = BsonContext( + codecRegistry = CodecRegistries.fromCodecs( + AtomicBooleanCodec(), + AtomicIntegerCodec(), + AtomicLongCodec(), + BigDecimalCodec(), + BinaryCodec(), + BooleanCodec(), + BsonArrayCodec(), + BsonBinaryCodec(), + BsonBooleanCodec(), + BsonDateTimeCodec(), + BsonDBPointerCodec(), + BsonDecimal128Codec(), + BsonDocumentCodec(), + BsonDoubleCodec(), + BsonInt32Codec(), + BsonInt64Codec(), + BsonJavaScriptCodec(), + BsonMaxKeyCodec(), + BsonMinKeyCodec(), + BsonNullCodec(), + BsonObjectIdCodec(), + BsonRegularExpressionCodec(), + BsonStringCodec(), + BsonSymbolCodec(), + BsonTimestampCodec(), + BsonUndefinedCodec(), + BsonValueCodec(), + ByteArrayCodec(), + ByteCodec(), + CharacterCodec(), + CodeCodec(), + DateCodec(), + Decimal128Codec(), + DocumentCodec(), + DoubleCodec(), + FloatCodec(), + InstantCodec(), + IntegerCodec(), + JsonObjectCodec(), + LocalDateCodec(), + LocalDateTimeCodec(), + LocalTimeCodec(), + LongCodec(), + MaxKeyCodec(), + MinKeyCodec(), + ObjectIdCodec(), + OverridableUuidRepresentationUuidCodec(), + PatternCodec(), + RawBsonDocumentCodec(), + ShortCodec(), + StringCodec(), + SymbolCodec(), + UuidCodec(), + ) +) diff --git a/prototype/dsl/src/test/kotlin/expr/ExpressionTestUtils.kt b/prototype/dsl/src/test/kotlin/expr/ExpressionTestUtils.kt deleted file mode 100644 index ebe90a99..00000000 --- a/prototype/dsl/src/test/kotlin/expr/ExpressionTestUtils.kt +++ /dev/null @@ -1,74 +0,0 @@ -package fr.qsh.ktmongo.dsl.expr - -import io.kotest.matchers.shouldBe -import org.bson.codecs.* -import org.bson.codecs.configuration.CodecRegistries -import org.bson.codecs.configuration.CodecRegistry -import org.bson.codecs.jsr310.InstantCodec -import org.bson.codecs.jsr310.LocalDateCodec -import org.bson.codecs.jsr310.LocalDateTimeCodec -import org.bson.codecs.jsr310.LocalTimeCodec - -fun testCodec(): CodecRegistry = CodecRegistries.fromCodecs( - AtomicBooleanCodec(), - AtomicIntegerCodec(), - AtomicLongCodec(), - BigDecimalCodec(), - BinaryCodec(), - BooleanCodec(), - BsonArrayCodec(), - BsonBinaryCodec(), - BsonBooleanCodec(), - BsonDateTimeCodec(), - BsonDBPointerCodec(), - BsonDecimal128Codec(), - BsonDocumentCodec(), - BsonDoubleCodec(), - BsonInt32Codec(), - BsonInt64Codec(), - BsonJavaScriptCodec(), - BsonMaxKeyCodec(), - BsonMinKeyCodec(), - BsonNullCodec(), - BsonObjectIdCodec(), - BsonRegularExpressionCodec(), - BsonStringCodec(), - BsonSymbolCodec(), - BsonTimestampCodec(), - BsonUndefinedCodec(), - BsonValueCodec(), - ByteArrayCodec(), - ByteCodec(), - CharacterCodec(), - CodeCodec(), - DateCodec(), - Decimal128Codec(), - DocumentCodec(), - DoubleCodec(), - FloatCodec(), - InstantCodec(), - IntegerCodec(), - JsonObjectCodec(), - LocalDateCodec(), - LocalDateTimeCodec(), - LocalTimeCodec(), - LongCodec(), - MaxKeyCodec(), - MinKeyCodec(), - ObjectIdCodec(), - OverridableUuidRepresentationUuidCodec(), - PatternCodec(), - RawBsonDocumentCodec(), - ShortCodec(), - StringCodec(), - SymbolCodec(), - UuidCodec(), -) - -infix fun String.shouldBeBson(expected: String) { - this shouldBe expected - .replace("\n", "") - .replace("\t", "") - .replace(",", ", ") - .replace(" ", " ") -} -- 2.51.2