mirror of
https://github.com/typeable/inflections-hs.git
synced 2024-08-15 17:10:21 +03:00
Add more tests
This commit is contained in:
parent
2a2d02847e
commit
0a43bc0690
@ -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
|
||||
|
@ -1,3 +1,6 @@
|
||||
resolver: lts-7.13
|
||||
packages:
|
||||
- '.'
|
||||
extra-deps:
|
||||
- hspec-megaparsec-0.3.0
|
||||
- megaparsec-5.1.2
|
||||
|
8
test/Text/Inflections/Parse/CamelCaseSpec.hs
Normal file
8
test/Text/Inflections/Parse/CamelCaseSpec.hs
Normal file
@ -0,0 +1,8 @@
|
||||
module Text.Inflections.Parse.CamelCaseSpec
|
||||
( spec )
|
||||
where
|
||||
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = return ()
|
8
test/Text/Inflections/Parse/SnakeCaseSpec.hs
Normal file
8
test/Text/Inflections/Parse/SnakeCaseSpec.hs
Normal file
@ -0,0 +1,8 @@
|
||||
module Text.Inflections.Parse.SnakeCaseSpec
|
||||
( spec )
|
||||
where
|
||||
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = return ()
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user