From 9ea9fa01c8c4218a90eaf8dd74ec5e2f78613e08 Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Mon, 7 Oct 2019 12:02:33 +0200 Subject: Port UTF8 js test suite to elixir --- test/elixir/README.md | 2 +- test/elixir/test/utf8_test.exs | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/elixir/test/utf8_test.exs 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 -- cgit v1.2.1