Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 0 additions & 84 deletions src/mango/test/21-empty-selector-tests.py

This file was deleted.

11 changes: 11 additions & 0 deletions test/elixir/test/config/search.elixir
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
22 changes: 22 additions & 0 deletions test/elixir/test/config/suite.elixir
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
128 changes: 128 additions & 0 deletions test/elixir/test/mango/21_empty_selector_test.exs
Original file line number Diff line number Diff line change
@@ -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