From 4be60d90a770712c3e32ff1e96a511e59c0aca04 Mon Sep 17 00:00:00 2001 From: Daniel Slapman Date: Sat, 18 Jan 2025 19:57:47 +0100 Subject: [PATCH] Test on a dynamic query with non-constant value --- .../test/scala/oolong/mongo/QuerySpec.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/oolong-mongo/src/test/scala/oolong/mongo/QuerySpec.scala b/oolong-mongo/src/test/scala/oolong/mongo/QuerySpec.scala index 14ce208..4eb984c 100644 --- a/oolong-mongo/src/test/scala/oolong/mongo/QuerySpec.scala +++ b/oolong-mongo/src/test/scala/oolong/mongo/QuerySpec.scala @@ -1229,6 +1229,25 @@ class QuerySpec extends AnyFunSuite { ) } + test("Conditional query with Pattern does not require lifting spec") { + case class NameTest(name: String) + + val nOp = Option("some_name") + val q = nOp.map { n => + query[NameTest](nt => Pattern.compile(n, Pattern.CASE_INSENSITIVE).matcher(nt.name).matches()) + } + val repr = renderQuery[NameTest](_.name == "some_name") + + test( + q.getOrElse(BsonDocument()), + repr, + BsonDocument( + "name" -> BsonDocument("$regex" -> BsonString("some_name"), "$options" -> BsonString("i")) + ), + ignoreRender = true + ) + } + private inline def test( query: BsonDocument, repr: String,