@@ -3,22 +3,37 @@
33module Text.InflectionsSpec (spec) where
44
55import Test.Hspec
6−import Text.Inflections (toUnderscore, toDashed, toCamelCased)
6+import Test.QuickCheck
7+import Text.Inflections
78
89spec :: Spec
910spec = do
11+
1012 describe "toUnderscore" $ do
1113 it "converts camel case to snake case" $
1214 toUnderscore "camelCasedText" `shouldBe` Right "camel_cased_text"
1315 it "converts camel case to snake case with numbers" $
1416 toUnderscore "ipv4Address" `shouldBe` Right "ipv4_address"
17+
1518 describe "toDashed" $
1619 it "converts camel case to dashed" $
1720 toDashed "camelCasedText" `shouldBe` Right "camel-cased-text"
21+
1822 describe "toCamelCased" $ do
1923 context "when the first argument is False" $
2024 it "converts snake case to camel case" $
2125 toCamelCased False "underscored_text" `shouldBe` Right "underscoredText"
2226 context "when the first argument is True" $
23− it "converts snake case to camel case" $
27+ it "converts snake case to camel case with the first word capitalized" $
2428 toCamelCased True "underscored_text" `shouldBe` Right "UnderscoredText"
29+
30+ describe "betterThrow" $ do
31+ context "when given a parse error" $
32+ it "throws the correct exception" $
33+ property $ \err ->
34+ betterThrow (Left err) `shouldThrow`
35+ (== InflectionParsingFailed err)
36+ context "when given a value in Right" $
37+ it "returns the value" $
38+ property $ \x ->
39+ betterThrow (Right x) `shouldReturn` (x :: Int)