diff --git a/src/mango/test/21-empty-selector-tests.py b/src/mango/test/21-empty-selector-tests.py deleted file mode 100644 index c5e6dee260a..00000000000 --- a/src/mango/test/21-empty-selector-tests.py +++ /dev/null @@ -1,84 +0,0 @@ -# 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. - -import mango -import unittest -import user_docs - - -class EmptySelectorTests: - def test_empty(self): - resp = self.db.find({}, explain=True) - self.assertEqual(resp["index"]["type"], "special") - - def test_empty_array_or(self): - resp = self.db.find({"$or": []}, explain=True) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"$or": []}) - assert len(docs) == 0 - - def test_empty_array_or_with_age(self): - resp = self.db.find({"age": 22, "$or": []}, explain=True) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"age": 22, "$or": []}) - assert len(docs) == 1 - - def test_empty_array_in_with_age(self): - resp = self.db.find({"age": 22, "company": {"$in": []}}, explain=True) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"age": 22, "company": {"$in": []}}) - assert len(docs) == 0 - - def test_empty_array_and_with_age(self): - resp = self.db.find({"age": 22, "$and": []}, explain=True) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"age": 22, "$and": []}) - assert len(docs) == 1 - - def test_empty_array_all_age(self): - resp = self.db.find({"age": 22, "company": {"$all": []}}, explain=True) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"age": 22, "company": {"$all": []}}) - assert len(docs) == 0 - - def test_empty_array_nested_all_with_age(self): - resp = self.db.find( - {"age": 22, "$and": [{"company": {"$all": []}}]}, explain=True - ) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"age": 22, "$and": [{"company": {"$all": []}}]}) - assert len(docs) == 0 - - def test_empty_arrays_complex(self): - resp = self.db.find({"$or": [], "a": {"$in": []}}, explain=True) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"$or": [], "a": {"$in": []}}) - assert len(docs) == 0 - - def test_empty_nin(self): - resp = self.db.find({"favorites": {"$nin": []}}, explain=True) - self.assertEqual(resp["index"]["type"], self.INDEX_TYPE) - docs = self.db.find({"favorites": {"$nin": []}}) - assert len(docs) == len(user_docs.DOCS) - - -class EmptySelectorNoIndexTests(mango.UserDocsTestsNoIndexes, EmptySelectorTests): - pass - - -@unittest.skipUnless(mango.has_text_service(), "requires text service") -class EmptySelectorTextTests(mango.UserDocsTextTests, EmptySelectorTests): - pass - - -class EmptySelectorUserDocTests(mango.UserDocsTests, EmptySelectorTests): - pass diff --git a/test/elixir/test/config/search.elixir b/test/elixir/test/config/search.elixir index 87715d4caf3..29f71dc3f76 100644 --- a/test/elixir/test/config/search.elixir +++ b/test/elixir/test/config/search.elixir @@ -33,6 +33,17 @@ "facet ranges, empty", "facet ranges, non-empty" ], + "EmptySelectorTextTests": [ + "empty", + "empty array or", + "empty array or with age", + "empty array in with age", + "empty array and with age", + "empty array all age", + "empty array nested all with age", + "empty arrays complex", + "empty nin" + ], "ElemMatchTests": [ "elem match non object" ], diff --git a/test/elixir/test/config/suite.elixir b/test/elixir/test/config/suite.elixir index b3fb950846c..480e5b9da76 100644 --- a/test/elixir/test/config/suite.elixir +++ b/test/elixir/test/config/suite.elixir @@ -735,5 +735,27 @@ ], "IgnoreDesignDocsForAllDocsIndexTests": [ "should not return design docs" + ], + "EmptySelectorUserDocTests": [ + "empty", + "empty array or", + "empty array or with age", + "empty array in with age", + "empty array and with age", + "empty array all age", + "empty array nested all with age", + "empty arrays complex", + "empty nin" + ], + "EmptySelectorNoIndexTests": [ + "empty", + "empty array or", + "empty array or with age", + "empty array in with age", + "empty array and with age", + "empty array all age", + "empty array nested all with age", + "empty arrays complex", + "empty nin" ] } diff --git a/test/elixir/test/mango/21_empty_selector_test.exs b/test/elixir/test/mango/21_empty_selector_test.exs new file mode 100644 index 00000000000..1c9d8e3072c --- /dev/null +++ b/test/elixir/test/mango/21_empty_selector_test.exs @@ -0,0 +1,128 @@ +# 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 EmptySelectorTests do + use CouchTestCase + + defmacro describe(db, index_type) do + quote do + test "empty" do + {:ok, resp} = MangoDatabase.find(unquote(db), %{}, explain: true) + assert resp["index"]["type"] == "special" + end + + test "empty array or" do + {:ok, resp} = MangoDatabase.find(unquote(db), %{"$or" => []}, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), %{"$or" => []}) + assert Enum.empty?(docs) + end + + test "empty array or with age" do + selector = %{"age" => 22, "$or" => []} + {:ok, resp} = MangoDatabase.find(unquote(db), selector, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), selector) + assert length(docs) == 1 + end + + test "empty array in with age" do + selector = %{"age" => 22, "company" => %{"$in" => []}} + {:ok, resp} = MangoDatabase.find(unquote(db), selector, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), selector) + assert Enum.empty?(docs) + end + + test "empty array and with age" do + selector = %{"age" => 22, "$and" => []} + {:ok, resp} = MangoDatabase.find(unquote(db), selector, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), selector) + assert length(docs) == 1 + end + + test "empty array all age" do + selector = %{"age" => 22, "company" => %{"$all" => []}} + {:ok, resp} = MangoDatabase.find(unquote(db), selector, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), selector) + assert Enum.empty?(docs) + end + + test "empty array nested all with age" do + selector = %{"age" => 22, "$and" => [%{"company" => %{"$all" => []}}]} + {:ok, resp} = MangoDatabase.find(unquote(db), selector, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), selector) + assert Enum.empty?(docs) + end + + test "empty arrays complex" do + selector = %{"$or" => [], "a" => %{"$in" => []}} + {:ok, resp} = MangoDatabase.find(unquote(db), selector, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), selector) + assert Enum.empty?(docs) + end + + test "empty nin" do + selector = %{"favorites" => %{"$nin" => []}} + {:ok, resp} = MangoDatabase.find(unquote(db), selector, explain: true) + assert resp["index"]["type"] == unquote(index_type) + + {:ok, docs} = MangoDatabase.find(unquote(db), selector) + assert length(docs) == UserDocs.len() + end + end + end +end + +defmodule EmptySelectorNoIndexTests do + use ExUnit.Case + require EmptySelectorTests + + setup do + db_name = "empty-selector-noindex" + UserDocs.setup(db_name, "special") + end + EmptySelectorTests.describe("empty-selector-noindex", "special") +end + +defmodule EmptySelectorTextTests do + use ExUnit.Case + require EmptySelectorTests + + setup do + db_name = "empty-selector-text" + UserDocs.setup(db_name, "text") + end + EmptySelectorTests.describe("empty-selector-text", "text") +end + +defmodule EmptySelectorUserDocTests do + use ExUnit.Case + require EmptySelectorTests + + setup do + db_name = "empty-selector" + UserDocs.setup(db_name) + end + EmptySelectorTests.describe("empty-selector", "json") +end