fluent-1.0.0: test/MessageSpec.hs
module MessageSpec (spec) where
import Prelude
spec :: Spec
spec = do
describe "value" do
it "is the text after the equals sign" $
translate "foo" [fluent|foo = Foo|] `shouldBe` Right "Foo"
it "keeps the whitespace inside it" $
translate "foo" [fluent|foo = Foo Bar|] `shouldBe` Right "Foo Bar"
it "drops the whitespace around it" $
translate "foo" [fluent|foo = Foo |] `shouldBe` Right "Foo"
it "may be empty of everything but a placeable" $
translate "foo" [fluent|foo = { "" }|] `shouldBe` Right ""
it "is missing when the message only has attributes" $
translate
"foo"
[fluent|
foo =
.attr = Attribute
|]
`shouldBe` Left "Message has no value: \"foo\""
it "is missing when the message does not exist" $
translate "bar" [fluent|foo = Foo|]
`shouldBe` Left "Message not found: \"bar\""
describe "attribute" do
it "is the text after the equals sign" $
translate
"foo.attr"
[fluent|
foo = Foo
.attr = Attribute
|]
`shouldBe` Right "Attribute"
it "is one of several" $
translate
"foo.two"
[fluent|
foo = Foo
.one = One
.two = Two
|]
`shouldBe` Right "Two"
it "belongs to a message without a value" $
translate
"foo.attr"
[fluent|
foo =
.attr = Attribute
|]
`shouldBe` Right "Attribute"
it "is missing when the message does not have it" $
translate "foo.attr" [fluent|foo = Foo|]
`shouldBe` Left "Attribute not found: \"attr\""
describe "identifier" do
it "holds letters, digits, dashes and underscores" $
translate "foo-bar_1" [fluent|foo-bar_1 = Ok|] `shouldBe` Right "Ok"
it "cannot hold a space in a reference" $
translate "not a name" [fluent|foo = Foo|]
`shouldBe` Left "Invalid reference: \"not a name\""
it "cannot hold a space in an argument name" $
translate "foo" ("not a name", "Bar" :: Text) [fluent|foo = { $arg }|]
`shouldBe` Left "Invalid identifier: \"not a name\""
it "keeps the first message when reused" $
translate
"foo"
[fluent|
foo = First
foo = Second
|]
`shouldBe` Right "First"
describe "several lines" do
it "are joined by the line breaks between them" $
translate
"foo"
[fluent|
foo =
Foo
Bar
|]
`shouldBe` Right "Foo\nBar"
it "lose the indent they share" $
translate
"foo"
[fluent|
foo =
Foo
Bar
|]
`shouldBe` Right "Foo\n Bar"
it "keep the blank lines between them" $
translate
"foo"
[fluent|
foo =
Foo
Bar
|]
`shouldBe` Right "Foo\n\nBar"
it "may start on the line of the identifier" $
translate
"foo"
[fluent|
foo = Foo
Bar
|]
`shouldBe` Right "Foo\nBar"
it "may begin with a placeable, which begins no line of its own" $
translate
"foo"
[fluent|
foo =
{ "Bar" }
Baz
|]
`shouldBe` Right "Bar\nBaz"
it "may hold a placeable of their own" $
translate
"foo"
[fluent|
foo =
Foo
{ "Bar" }
|]
`shouldBe` Right "Foo\nBar"