-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmemorized_vocabulary_test.exs
55 lines (45 loc) · 1.68 KB
/
memorized_vocabulary_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
defmodule MemorizedVocabularyTest do
use ExUnit.Case
setup do
Linguist.MemorizedVocabulary.locale("es", Path.join([__DIR__, "es.yml"]))
Linguist.MemorizedVocabulary.locale("fr-FR", Path.join([__DIR__, "fr-FR.yml"]))
:ok
end
test "locales() returns locales" do
assert ["fr-FR", "es"] == Linguist.MemorizedVocabulary.locales()
end
test "t returns a translation" do
assert {:ok, "bar"} == Linguist.MemorizedVocabulary.t("es", "foo")
end
test "t interpolates values" do
assert {:ok, "hola Michael Westin"} ==
Linguist.MemorizedVocabulary.t(
"es",
"flash.notice.hello",
first: "Michael",
last: "Westin"
)
end
test "t returns {:error, :no_translation} when translation is missing" do
assert Linguist.MemorizedVocabulary.t("es", "flash.not_exists") == {:error, :no_translation}
end
test "t! raises NoTranslationError when translation is missing" do
assert_raise Linguist.NoTranslationError, fn ->
Linguist.MemorizedVocabulary.t!("es", "flash.not_exists")
end
end
test "t pluralizes" do
assert {:ok, "2 manzanas"} == Linguist.MemorizedVocabulary.t("es", "apple", count: 2)
end
test "t will normalize a locale to format ll-LL" do
assert {:ok, "Ennui"} == Linguist.MemorizedVocabulary.t("FR-fr", "flash.notice.alert")
end
test "t will raise a LocaleError if a malformed locale is passed in" do
assert_raise Linguist.LocaleError, fn ->
Linguist.MemorizedVocabulary.t("es-es-es", "flash.notice.alert")
end
assert_raise Linguist.LocaleError, fn ->
Linguist.MemorizedVocabulary.t(nil, "flash.notice.alert")
end
end
end