Keep public interface small

This commit is contained in:
Justin Leitgeb 2014-03-05 15:56:40 -05:00
parent 7a6f2525a7
commit 42a5ccd68c
4 changed files with 27 additions and 20 deletions

View File

@ -9,14 +9,15 @@ import qualified Text.Parsec as P
import Text.Inflections.Parse.Types (Word(..))
import Text.Inflections.Parse.Acronym (acronym)
word :: P.Stream s m Char => P.ParsecT s u m Word
word = do
firstChar <- C.upper P.<|> C.lower
restChars <- P.many C.lower
return $ Word $ firstChar : restChars
-- |Recognizes an input String in CamelCase.
parser :: P.Stream s m Char => [String] -> P.ParsecT s u m [Word]
parser acronyms = do
ws <- P.many $ P.choice [ acronym acronyms, word ]
P.eof
return ws
word :: P.Stream s m Char => P.ParsecT s u m Word
word = do
firstChar <- C.upper P.<|> C.lower
restChars <- P.many C.lower
return $ Word $ firstChar : restChars

View File

@ -20,16 +20,19 @@ source-repository head
library
exposed-modules: Text.Inflections
, Text.Inflections.Parse.CamelCase
, Text.Inflections.Parse.SnakeCase
, Text.Inflections.Parse.Parameterizable
, Text.Inflections.Parse.Types
other-modules: Text.Inflections.Data
, Text.Inflections.Parameterize
, Text.Inflections.Underscore
, Text.Inflections.Camelize
, Text.Inflections.Parse.Acronym
, Text.Inflections.Dasherize
, Text.Inflections.Parse.Acronym
, Text.Inflections.Parse.SnakeCase
, Text.Inflections.Parse.Parameterizable
, Text.Inflections.Parse.CamelCase
, Text.Inflections.Parse.Types
ghc-options: -Wall
build-depends: base >=4.5 && <4.7, parsec, containers
default-language: Haskell2010

View File

@ -3,8 +3,8 @@ module Main where
import Test.Framework (defaultMain)
import qualified Text.Inflections.Tests
import qualified Text.Inflections.Parse.CamelCaseTest
import qualified Text.Inflections.UnderscoreTest
main :: IO ()
main = defaultMain $ Text.Inflections.Tests.tests ++
Text.Inflections.Parse.CamelCaseTest.tests
Text.Inflections.UnderscoreTest.tests

View File

@ -1,4 +1,4 @@
module Text.Inflections.Parse.CamelCaseTest where
module Text.Inflections.UnderscoreTest where
import Test.HUnit hiding (Test)
@ -16,8 +16,7 @@ import Data.Map (fromList)
import Text.Parsec
import Data.Maybe (fromJust)
import Text.Inflections.Parse.CamelCase
import Text.Inflections.Parse.Types
import Text.Inflections (underscore)
{-# ANN module "HLint: ignore Use camelCase" #-}
@ -25,6 +24,7 @@ tests :: [Test]
tests = [testGroup "parsing"
[ testCase "lower-camel case" test_lowerCamelCase
, testCase "upper-camel case" test_upperCamelCase
, testCase "invalid camel case" test_failedUnderscore
]
]
@ -33,8 +33,11 @@ fromRight (Left _) =
error "Either.Unwrap.fromRight: Argument takes form 'Left _'"
fromRight (Right x) = x
test_lowerCamelCase = fromRight (parse (parser []) "" "testThis") @?=
[Word "test", Word "This"]
isLeft :: Either a b -> Bool
isLeft (Left _) = True
isLeft (Right _) = False
test_upperCamelCase = fromRight (parse (parser []) "" "TestThis") @?=
[Word "Test", Word "This"]
test_lowerCamelCase = fromRight (underscore "testThis") @?= "test_this"
test_upperCamelCase = fromRight (underscore "TestThis") @?= "test_this"
test_failedUnderscore = True @?= (isLeft $ underscore "hey there")