diff --git a/inflections.cabal b/inflections.cabal index 7ed9b17..12ce9ef 100644 --- a/inflections.cabal +++ b/inflections.cabal @@ -62,7 +62,8 @@ test-suite test , QuickCheck >= 2.7.6 && < 3.0 , base >= 4.6 && < 5.0 , hspec >= 2.0 && < 3.0 - , megaparsec >= 5.0 && < 6.0 + , hspec-megaparsec >= 0.3 && < 0.4 + , megaparsec >= 5.1 && < 6.0 , text >= 0.2 && < 1.3 if flag(dev) ghc-options: -Wall -Werror @@ -73,6 +74,8 @@ test-suite test , Text.Inflections.HumanizeSpec , Text.Inflections.OrdinalSpec , Text.Inflections.ParametrizeSpec + , Text.Inflections.Parse.CamelCaseSpec + , Text.Inflections.Parse.SnakeCaseSpec , Text.Inflections.TitleizeSpec , Text.Inflections.TransliterateSpec , Text.Inflections.UnderscoreSpec diff --git a/stack.yaml b/stack.yaml index 36801c9..9085c49 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,6 @@ resolver: lts-7.13 packages: - '.' +extra-deps: +- hspec-megaparsec-0.3.0 +- megaparsec-5.1.2 diff --git a/test/Text/Inflections/Parse/CamelCaseSpec.hs b/test/Text/Inflections/Parse/CamelCaseSpec.hs new file mode 100644 index 0000000..ac2d2f3 --- /dev/null +++ b/test/Text/Inflections/Parse/CamelCaseSpec.hs @@ -0,0 +1,8 @@ +module Text.Inflections.Parse.CamelCaseSpec + ( spec ) +where + +import Test.Hspec + +spec :: Spec +spec = return () diff --git a/test/Text/Inflections/Parse/SnakeCaseSpec.hs b/test/Text/Inflections/Parse/SnakeCaseSpec.hs new file mode 100644 index 0000000..d4fb069 --- /dev/null +++ b/test/Text/Inflections/Parse/SnakeCaseSpec.hs @@ -0,0 +1,8 @@ +module Text.Inflections.Parse.SnakeCaseSpec + ( spec ) +where + +import Test.Hspec + +spec :: Spec +spec = return () diff --git a/test/Text/InflectionsSpec.hs b/test/Text/InflectionsSpec.hs index fd9b335..2b0f739 100644 --- a/test/Text/InflectionsSpec.hs +++ b/test/Text/InflectionsSpec.hs @@ -3,22 +3,37 @@ module Text.InflectionsSpec (spec) where import Test.Hspec -import Text.Inflections (toUnderscore, toDashed, toCamelCased) +import Test.QuickCheck +import Text.Inflections spec :: Spec spec = do + describe "toUnderscore" $ do it "converts camel case to snake case" $ toUnderscore "camelCasedText" `shouldBe` Right "camel_cased_text" it "converts camel case to snake case with numbers" $ toUnderscore "ipv4Address" `shouldBe` Right "ipv4_address" + describe "toDashed" $ it "converts camel case to dashed" $ toDashed "camelCasedText" `shouldBe` Right "camel-cased-text" + describe "toCamelCased" $ do context "when the first argument is False" $ it "converts snake case to camel case" $ toCamelCased False "underscored_text" `shouldBe` Right "underscoredText" context "when the first argument is True" $ - it "converts snake case to camel case" $ + it "converts snake case to camel case with the first word capitalized" $ toCamelCased True "underscored_text" `shouldBe` Right "UnderscoredText" + + describe "betterThrow" $ do + context "when given a parse error" $ + it "throws the correct exception" $ + property $ \err -> + betterThrow (Left err) `shouldThrow` + (== InflectionParsingFailed err) + context "when given a value in Right" $ + it "returns the value" $ + property $ \x -> + betterThrow (Right x) `shouldReturn` (x :: Int)