fluent-icu-1.0.0: test/PluralSpec.hs
module PluralSpec (spec) where
import Language.Fluent.ICU
import Prelude
spec :: Spec
spec = do
describe "English" do
it "counts one" $ translate "foo" ("arg", number 1) categories `shouldBe` Right "one"
it "counts two" $ translate "foo" ("arg", number 2) categories `shouldBe` Right "other"
it "counts zero" $ translate "foo" ("arg", number 0) categories `shouldBe` Right "other"
it "counts a fraction" $ translate "foo" ("arg", number 1.5) categories `shouldBe` Right "other"
it "counts the first" $ translate "foo" ("arg", ordinal 1) categories `shouldBe` Right "one"
it "counts the second" $ translate "foo" ("arg", ordinal 2) categories `shouldBe` Right "two"
it "counts the third" $ translate "foo" ("arg", ordinal 3) categories `shouldBe` Right "few"
it "counts the fourth" $ translate "foo" ("arg", ordinal 4) categories `shouldBe` Right "other"
it "counts the twenty second" $
translate "foo" ("arg", ordinal 22) categories `shouldBe` Right "two"
describe "other languages" do
it "counts twenty one in Russian" $
translate "foo" ("arg", number 21) ru categories `shouldBe` Right "one"
it "counts twenty two in Russian" $
translate "foo" ("arg", number 22) ru categories `shouldBe` Right "few"
it "counts five in Russian" $
translate "foo" ("arg", number 5) ru categories `shouldBe` Right "many"
it "counts two in Welsh" $
translate "foo" ("arg", number 2) cy categories `shouldBe` Right "two"
it "counts six in Welsh" $
translate "foo" ("arg", number 6) cy categories `shouldBe` Right "many"
it "counts zero in Arabic" $
translate "foo" ("arg", number 0) ar categories `shouldBe` Right "zero"
it "counts one hundred and three in Arabic" $
translate "foo" ("arg", number 103) ar categories `shouldBe` Right "few"
it "counts one in Japanese, which does not count" $
translate "foo" ("arg", number 1) ja categories `shouldBe` Right "other"
describe "a message written for one language" do
it "reads as a plural in English" $
translate "apples" ("count", number 2) apples `shouldBe` Right "2 apples"
it "reads as a singular in English" $
translate "apples" ("count", number 1) apples `shouldBe` Right "1 apple"
it "falls to the default in a language with more categories" $
translate "apples" ("count", number 5) ru apples `shouldBe` Right "5 apples"
ru, cy, ar, ja :: LocaleName
ru = "ru"
cy = "cy"
ar = "ar"
ja = "ja"
categories :: Resource
categories =
[fluent|
foo = { $arg ->
[zero] zero
[one] one
[two] two
[few] few
[many] many
*[other] other
}
|]
apples :: Resource
apples =
[fluent|
apples = { $count ->
[one] { $count } apple
*[other] { $count } apples
}
|]