This is an automated email from the ASF dual-hosted git repository.

nickva pushed a commit to branch test-for-mango-id-collation
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 6b0e3f2a010200a989a67913b448b1523252b23c
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Tue Sep 22 11:19:26 2026 -0400

    Add a test for mango ID collation
    
    This is a follow up to https://github.com/apache/couchdb/pull/6121
---
 test/elixir/test/config/suite.elixir            |  5 ++
 test/elixir/test/mango/26_id_collation_test.exs | 79 +++++++++++++++++++++++++
 2 files changed, 84 insertions(+)

diff --git a/test/elixir/test/config/suite.elixir 
b/test/elixir/test/config/suite.elixir
index c392fe8df..9d4ae53da 100644
--- a/test/elixir/test/config/suite.elixir
+++ b/test/elixir/test/config/suite.elixir
@@ -903,6 +903,11 @@
     "no matches",
     "case sensitivity"
   ],
+  "IdCollationTest": [
+    "_id range find is the same as _all_docs",
+    "_id range in _changes selector",
+    "icu collation for nested _id fields"
+  ],
   "JSONIndexSelectionTest": [
     "basic",
     "with and",
diff --git a/test/elixir/test/mango/26_id_collation_test.exs 
b/test/elixir/test/mango/26_id_collation_test.exs
new file mode 100644
index 000000000..697b2fba6
--- /dev/null
+++ b/test/elixir/test/mango/26_id_collation_test.exs
@@ -0,0 +1,79 @@
+# 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.
+
+defmodule IdCollationTest do
+  use CouchTestCase
+
+  @moduledoc """
+  Doc _id comparisons in selectors should be by byter order like _all_docs. 
Other
+  string fields are compared by ICU collation.
+  """
+
+  @db_name "id-collation"
+
+  # As compared with byte order. With ICU it would be
+  # [a1, b9, B0, m5, Z1, zed]
+  @ids ["B0", "Z1", "a1", "b9", "m5", "zed"]
+
+  setup do
+    MangoDatabase.recreate(@db_name)
+    docs = Enum.map(@ids, fn id -> %{"_id" => id, "a" => %{"_id" => id}} end)
+    MangoDatabase.save_docs(@db_name, docs)
+    :ok
+  end
+
+  defp find(selector) do
+    {:ok, docs} = MangoDatabase.find(@db_name, selector, fields: ["_id"])
+    Enum.map(docs, fn doc -> doc["_id"] end)
+  end
+
+  defp all_docs(query) do
+    resp = Couch.get("/#{@db_name}/_all_docs", query: query)
+    assert resp.status_code == 200
+    Enum.map(resp.body["rows"], fn row -> row["id"] end)
+  end
+
+  test "_id range find is the same as _all_docs" do
+    {:ok, explain} =
+      MangoDatabase.find(@db_name, %{"_id" => %{"$gte" => "Z"}}, explain: true)
+
+    assert explain["index"]["name"] == "_all_docs"
+
+    gte_z = find(%{"_id" => %{"$gte" => "Z"}})
+    assert gte_z == all_docs(%{:startkey => "\"Z\""})
+    assert gte_z == ["Z1", "a1", "b9", "m5", "zed"]
+
+    lt_a = find(%{"_id" => %{"$lt" => "a"}})
+    assert lt_a == all_docs(%{:endkey => "\"a\"", :inclusive_end => false})
+    assert lt_a == ["B0", "Z1"]
+
+    assert find(%{"_id" => %{"$gt" => "B0", "$lte" => "b9"}}) == ["Z1", "a1", 
"b9"]
+  end
+
+  test "_id range in _changes selector" do
+    resp =
+      Couch.post("/#{@db_name}/_changes?filter=_selector",
+        body: %{"selector" => %{"_id" => %{"$gte" => "Z"}}},
+        headers: ["Content-Type": "application/json"]
+      )
+
+    assert resp.status_code == 200
+
+    ids = Enum.sort(Enum.map(resp.body["results"], fn row -> row["id"] end))
+    assert ids == ["Z1", "a1", "b9", "m5", "zed"]
+  end
+
+  test "icu collation for nested _id fields" do
+    # a._id instead of the top level _id
+    assert find(%{"a._id" => %{"$gte" => "Z"}}) == ["Z1", "zed"]
+  end
+end

Reply via email to