git.iko.soy/typeable/inflections-hs
on master help sign in
Add more tests
commit0a43bc06903db88d27b33249766535efb374e61c authormrkkrp <markkarpov@opmbx.org> dateWed 21 Dec 2016, 16:17 (10 years ago) parent2a2d028
5 files changed+40−3
inflections.cabal+4−1 stack.yaml+3 test/Text/Inflections/Parse/CamelCaseSpec.hs+8 test/Text/Inflections/Parse/SnakeCaseSpec.hs+8 test/Text/InflectionsSpec.hs+17−2
inflections.cabal+4−1
@@ -62,7 +62,8 @@ test-suite test
6262 , QuickCheck >= 2.7.6 && < 3.0
6363 , base >= 4.6 && < 5.0
6464 , hspec >= 2.0 && < 3.0
65− , megaparsec >= 5.0 && < 6.0
65+ , hspec-megaparsec >= 0.3 && < 0.4
66+ , megaparsec >= 5.1 && < 6.0
6667 , text >= 0.2 && < 1.3
6768 if flag(dev)
6869 ghc-options: -Wall -Werror
@@ -73,6 +74,8 @@ test-suite test
7374 , Text.Inflections.HumanizeSpec
7475 , Text.Inflections.OrdinalSpec
7576 , Text.Inflections.ParametrizeSpec
77+ , Text.Inflections.Parse.CamelCaseSpec
78+ , Text.Inflections.Parse.SnakeCaseSpec
7679 , Text.Inflections.TitleizeSpec
7780 , Text.Inflections.TransliterateSpec
7881 , Text.Inflections.UnderscoreSpec
stack.yaml+3
@@ -1,3 +1,6 @@
11resolver: lts-7.13
22packages:
33- '.'
4+extra-deps:
5+- hspec-megaparsec-0.3.0
6+- megaparsec-5.1.2
test/Text/Inflections/Parse/CamelCaseSpec.hsnew file+8
@@ -0,0 +1,8 @@
1+module Text.Inflections.Parse.CamelCaseSpec
2+ ( spec )
3+where
4+
5+import Test.Hspec
6+
7+spec :: Spec
8+spec = return ()
test/Text/Inflections/Parse/SnakeCaseSpec.hsnew file+8
@@ -0,0 +1,8 @@
1+module Text.Inflections.Parse.SnakeCaseSpec
2+ ( spec )
3+where
4+
5+import Test.Hspec
6+
7+spec :: Spec
8+spec = return ()
test/Text/InflectionsSpec.hs+17−2
@@ -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)