packages feed

fluent-1.0.0: test/LiteralSpec.hs

module LiteralSpec (spec) where

import Prelude

spec :: Spec
spec = do
    describe "string" do
        it "is placed" $
            translate "foo" [fluent|foo = { "Foo" }|] `shouldBe` Right "Foo"
        it "may be empty" $
            translate "foo" [fluent|foo = A{ "" }B|] `shouldBe` Right "AB"
        it "keeps the whitespace inside it" $
            translate "foo" [fluent|foo = {"  "}Foo|] `shouldBe` Right "  Foo"
        it "escapes a quote" $
            translate "foo" [fluent|foo = { "\"" }|] `shouldBe` Right "\""
        it "escapes a backslash" $
            translate "foo" [fluent|foo = { "\\" }|] `shouldBe` Right "\\"
        it "escapes a character by its four digit code" $
            translate "foo" [fluent|foo = { "\u0041" }|] `shouldBe` Right "A"
        it "escapes a character by its six digit code" $
            translate "foo" [fluent|foo = { "\U01F602" }|] `shouldBe` Right "\128514"
        it "escapes a brace, which cannot be written on its own" $
            translate "foo" [fluent|foo = { "{" }Foo|] `shouldBe` Right "{Foo"

    describe "number" do
        it "is placed" $
            translate "foo" [fluent|foo = { 3 }|] `shouldBe` Right "3"
        it "is negative" $
            translate "foo" [fluent|foo = { -3 }|] `shouldBe` Right "-3"
        it "keeps the fraction digits it was written with" $
            translate "foo" [fluent|foo = { 0.50 }|] `shouldBe` Right "0.50"
        it "keeps every digit it was written with, however many" $
            translate "foo" [fluent|foo = { 0.1234 }|] `shouldBe` Right "0.1234"
        it "keeps every digit of a number of many, which the locale is left to group" $
            translate "foo" [fluent|foo = { 1234567 }|] `shouldBe` Right "1234567"

    describe "placeable" do
        it "holds a placeable of its own" $
            translate "foo" [fluent|foo = { { 3 } }|] `shouldBe` Right "3"
        it "stands between texts" $
            translate "foo" [fluent|foo = Foo { "Bar" } Baz|] `shouldBe` Right "Foo Bar Baz"
        it "stands on a line of its own" $
            translate
                "foo"
                [fluent|
                  foo =
                      Foo
                      { "Bar" }
                      Baz
                |]
                `shouldBe` Right "Foo\nBar\nBaz"