commit
0d8439c5cd
4 changed files with 37 additions and 4 deletions
|
@ -33,3 +33,16 @@ library
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
||||||
|
|
||||||
|
test-suite spec
|
||||||
|
type: exitcode-stdio-1.0
|
||||||
|
hs-source-dirs: test
|
||||||
|
ghc-options: -Wall
|
||||||
|
main-is: Spec.hs
|
||||||
|
other-modules:
|
||||||
|
Servant.ForeignSpec
|
||||||
|
build-depends: base
|
||||||
|
, hspec >= 2.1.8
|
||||||
|
, servant-foreign
|
||||||
|
default-language: Haskell2010
|
|
@ -47,6 +47,7 @@ module Servant.Foreign
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Lens (makeLenses, (%~), (&), (.~), (<>~))
|
import Control.Lens (makeLenses, (%~), (&), (.~), (<>~))
|
||||||
|
import qualified Data.Char as C
|
||||||
import Data.Proxy
|
import Data.Proxy
|
||||||
import Data.Text
|
import Data.Text
|
||||||
import GHC.Exts (Constraint)
|
import GHC.Exts (Constraint)
|
||||||
|
@ -66,10 +67,11 @@ snakeCase = intercalate "_"
|
||||||
-- | Function name builder using the CamelCase convention.
|
-- | Function name builder using the CamelCase convention.
|
||||||
-- each part begins with an upper case character.
|
-- each part begins with an upper case character.
|
||||||
camelCase :: FunctionName -> Text
|
camelCase :: FunctionName -> Text
|
||||||
camelCase [] = ""
|
camelCase = camelCase' . Prelude.map (replace "-" "")
|
||||||
camelCase (p:ps) = concat $ p : camelCase' ps
|
where camelCase' [] = ""
|
||||||
where camelCase' [] = []
|
camelCase' (p:ps) = concat $ p : Prelude.map capitalize ps
|
||||||
camelCase' (r:rs) = toUpper r : camelCase' rs
|
capitalize "" = ""
|
||||||
|
capitalize name = C.toUpper (Data.Text.head name) `cons` Data.Text.tail name
|
||||||
|
|
||||||
type Arg = Text
|
type Arg = Text
|
||||||
|
|
||||||
|
|
17
servant-foreign/test/Servant/ForeignSpec.hs
Normal file
17
servant-foreign/test/Servant/ForeignSpec.hs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
|
module Servant.ForeignSpec where
|
||||||
|
|
||||||
|
import Servant.Foreign (camelCase)
|
||||||
|
|
||||||
|
import Test.Hspec
|
||||||
|
|
||||||
|
spec :: Spec
|
||||||
|
spec = describe "Servant.Foreign" $ do
|
||||||
|
camelCaseSpec
|
||||||
|
|
||||||
|
camelCaseSpec :: Spec
|
||||||
|
camelCaseSpec = describe "camelCase" $ do
|
||||||
|
it "converts FunctionNames to camelCase" $ do
|
||||||
|
camelCase ["post", "counter", "inc"] `shouldBe` "postCounterInc"
|
||||||
|
camelCase ["get", "hyphen-ated", "counter"] `shouldBe` "getHyphenatedCounter"
|
1
servant-foreign/test/Spec.hs
Normal file
1
servant-foreign/test/Spec.hs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
|
Loading…
Reference in a new issue