Skip to content

Commit

Permalink
test: add tests for other scripts and emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
cschmatzler committed Sep 3, 2023
1 parent fbaf344 commit 2b49a13
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
18 changes: 17 additions & 1 deletion test/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Natural language: the colon-ing": "Colons",
"carrot_one": "1 carrot",
"carrot_other": "{{count}} carrots",
"welcome": "welcome, {{name}}"
"welcome": "welcome, {{name}}",
"Welcome to our site 😊": "Welcome to our site 😊"
},
"signup": {
"create.account": "Create your account"
Expand All @@ -30,5 +31,20 @@
"default": {
"hello": "bonjour"
}
},
"ar": {
"default": {
"Hello world": "مرحبا بالعالم"
}
},
"zh": {
"default": {
"Hello world": "你好世界"
}
},
"ja": {
"default": {
"Hello world": "こんにちは世界"
}
}
}
34 changes: 20 additions & 14 deletions test/idiom/cache/init_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,25 @@ defmodule Idiom.Cache.InitTest do

Cache.init(data)

assert Map.new(:ets.tab2list(default_table_name)) == %{
{"de", "default", "butterfly"} => "Schmetterling",
{"de", "signup", "create.account"} => "Erstelle dein Konto",
{"en", "default", "Natural language: the colon-ing"} => "Colons",
{"en", "default", "carrot_one"} => "1 carrot",
{"en", "default", "carrot_other"} => "{{count}} carrots",
{"en", "default", "deep.foo"} => "Deep bar",
{"en", "default", "foo"} => "bar",
{"en", "default", "hello"} => "hello",
{"en", "default", "welcome"} => "welcome, {{name}}",
{"en", "signup", "create.account"} => "Create your account",
{"es", "default", "hello"} => "hola",
{"fr", "default", "hello"} => "bonjour"
}
assert :ets.tab2list(default_table_name)
|> Map.new() ==
%{
{"de", "default", "butterfly"} => "Schmetterling",
{"de", "signup", "create.account"} => "Erstelle dein Konto",
{"en", "default", "Natural language: the colon-ing"} => "Colons",
{"en", "default", "carrot_one"} => "1 carrot",
{"en", "default", "carrot_other"} => "{{count}} carrots",
{"en", "default", "deep.foo"} => "Deep bar",
{"en", "default", "foo"} => "bar",
{"en", "default", "hello"} => "hello",
{"en", "default", "welcome"} => "welcome, {{name}}",
{"en", "signup", "create.account"} => "Create your account",
{"es", "default", "hello"} => "hola",
{"fr", "default", "hello"} => "bonjour",
{"ar", "default", "Hello world"} => "مرحبا بالعالم",
{"en", "default", "Welcome to our site 😊"} => "Welcome to our site 😊",
{"ja", "default", "Hello world"} => "こんにちは世界",
{"zh", "default", "Hello world"} => "你好世界"
}
end
end
8 changes: 7 additions & 1 deletion test/idiom/idiom/t_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ defmodule Idiom.Idiom.TTest do
%{key: "carrot", opts: [count: 1, cache_table_name: :t_test], expected: "1 carrot"},
%{key: "carrot", opts: [count: 2, cache_table_name: :t_test], expected: "2 carrots"},
# With plural key and explicit suffix
%{key: "carrot_one", opts: [count: 2, cache_table_name: :t_test], expected: "1 carrot"}
%{key: "carrot_one", opts: [count: 2, cache_table_name: :t_test], expected: "1 carrot"},
# With different scripts
%{key: "Hello world", opts: [to: "ar", cache_table_name: :t_test], expected: "مرحبا بالعالم"},
%{key: "Hello world", opts: [to: "zh", cache_table_name: :t_test], expected: "你好世界"},
%{key: "Hello world", opts: [to: "ja", cache_table_name: :t_test], expected: "こんにちは世界"},
# With emoji
%{key: "Welcome to our site 😊", opts: [ cache_table_name: :t_test], expected: "Welcome to our site 😊"}
]

for %{key: key, opts: opts, expected: expected} <- tests do
Expand Down

0 comments on commit 2b49a13

Please sign in to comment.