From 185c506788342d7e1b1548acdc58556c1f8b9e59 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Fri, 16 Dec 2016 18:03:14 +0300 Subject: [PATCH] Allow Word to contain digits (#42) --- Text/Inflections/Parse/CamelCase.hs | 2 +- test/Text/InflectionsSpec.hs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Text/Inflections/Parse/CamelCase.hs b/Text/Inflections/Parse/CamelCase.hs index 9586695..6ef5571 100644 --- a/Text/Inflections/Parse/CamelCase.hs +++ b/Text/Inflections/Parse/CamelCase.hs @@ -51,6 +51,6 @@ parser acronyms = many (acronym acronyms <|> word) <* eof word :: Parser Word word = do firstChar <- upperChar <|> lowerChar - restChars <- many lowerChar + restChars <- many $ lowerChar <|> digitChar return . Word . T.pack $ firstChar : restChars {-# INLINE word #-} diff --git a/test/Text/InflectionsSpec.hs b/test/Text/InflectionsSpec.hs index 5f10fe3..e95a796 100644 --- a/test/Text/InflectionsSpec.hs +++ b/test/Text/InflectionsSpec.hs @@ -7,9 +7,11 @@ import Text.Inflections (toUnderscore, toDashed, toCamelCased) spec :: Spec spec = do - describe "toUnderscore" $ + describe "toUnderscore" $ do it "converts camel case to snake case" $ toUnderscore "camelCasedText" `shouldReturn` "camel_cased_text" + it "converts camel case to snake case with numbers" $ + toUnderscore "ipv4Address" `shouldReturn` "ipv4_address" describe "toDashed" $ it "converts camel case to dashed" $ toDashed "camelCasedText" `shouldReturn` "camel-cased-text"