summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Biancalana <dottorblaster@gmail.com>2019-10-07 12:02:33 +0200
committerJan Lehnardt <jan@apache.org>2020-01-04 17:51:03 +0100
commit9ea9fa01c8c4218a90eaf8dd74ec5e2f78613e08 (patch)
tree7674c1d41e9d95769d90ec58346f7ee666495efb
parent3f1f711b451d0fb2c841cc845b1937a573224caf (diff)
downloadcouchdb-9ea9fa01c8c4218a90eaf8dd74ec5e2f78613e08.tar.gz
Port UTF8 js test suite to elixir
-rw-r--r--test/elixir/README.md2
-rw-r--r--test/elixir/test/utf8_test.exs65
2 files changed, 66 insertions, 1 deletions
diff --git a/test/elixir/README.md b/test/elixir/README.md
index 7f13d8afc..c4aec6dff 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -95,7 +95,7 @@ X means done, - means partially
- [ ] Port update_documents.js
- [ ] Port users_db.js
- [ ] Port users_db_security.js
- - [ ] Port utf8.js
+ - [X] Port utf8.js
- [X] Port uuids.js
- [X] Port view_collation.js
- [ ] Port view_collation_raw.js
diff --git a/test/elixir/test/utf8_test.exs b/test/elixir/test/utf8_test.exs
new file mode 100644
index 000000000..41537101e
--- /dev/null
+++ b/test/elixir/test/utf8_test.exs
@@ -0,0 +1,65 @@
+defmodule UTF8Test do
+ use CouchTestCase
+
+ @moduletag :utf8
+
+ @moduledoc """
+ Test CouchDB UTF8 support
+ This is a port of the utf8.js test suite
+ """
+
+ @tag :with_db
+ test "UTF8 support", context do
+ db_name = context[:db_name]
+ texts = [
+ "1. Ascii: hello",
+ "2. Russian: На берегу пустынных волн",
+ "3. Math: ∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i),",
+ "4. Geek: STARGΛ̊TE SG-1",
+ "5. Braille: ⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌",
+ "6. null \u0000 byte",
+ ]
+
+ texts
+ |> Enum.with_index()
+ |> Enum.each(fn {string, index} ->
+ status = Couch.post("/#{db_name}", query: [w: 3], body: %{"_id" => Integer.to_string(index), "text" => string}).status_code
+ assert status == 201
+ end)
+
+ texts
+ |> Enum.with_index()
+ |> Enum.each(fn {string, index} ->
+ resp = Couch.get("/#{db_name}/#{index}")
+ %{"_id" => id, "text" => text} = resp.body
+ assert resp.status_code == 200
+ assert Enum.at(texts, String.to_integer(id)) === text
+ end)
+
+ design_doc = %{
+ :_id => "_design/temp_utf8_support",
+ :language => "javascript",
+ :views => %{
+ :view => %{
+ :map => "function(doc) { emit(null, doc.text) }"
+ }
+ }
+ }
+
+ design_resp =
+ Couch.put(
+ "/#{db_name}/_design/temp_utf8_support",
+ body: design_doc,
+ query: %{w: 3}
+ )
+
+ assert design_resp.status_code in [201, 202]
+
+ %{"rows" => values} = Couch.get("/#{db_name}/_design/temp_utf8_support/_view/view").body
+ values
+ |> Enum.with_index()
+ |> Enum.each(fn {%{"value" => value}, index} ->
+ assert Enum.at(texts, index) === value
+ end)
+ end
+end