From 58b27cd95766e56c0d67ff8c82c2b19b8c462969 Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Wed, 24 Dec 2014 13:55:25 +0100 Subject: [PATCH] Fix dot in function name issue. --- servant-jquery.cabal | 15 ++++++++++++++- src/Servant/JQuery/Internal.hs | 2 +- test/Servant/JQuerySpec.hs | 29 +++++++++++++++++++++++++++++ test/Spec.hs | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/Servant/JQuerySpec.hs create mode 100644 test/Spec.hs diff --git a/servant-jquery.cabal b/servant-jquery.cabal index f33b510b..86d0a591 100644 --- a/servant-jquery.cabal +++ b/servant-jquery.cabal @@ -37,7 +37,7 @@ executable counter main-is: counter.hs ghc-options: -O2 -Wall hs-source-dirs: examples - + if flag(example) buildable: True else @@ -54,3 +54,16 @@ executable counter , transformers , warp default-language: Haskell2010 + +test-suite spec + type: exitcode-stdio-1.0 + hs-source-dirs: test + ghc-options: -Wall + main-is: Spec.hs + build-depends: + base == 4.* + , servant-jquery + , servant + , hspec >= 2.0 + , language-ecmascript == 0.16.* + default-language: Haskell2010 diff --git a/src/Servant/JQuery/Internal.hs b/src/Servant/JQuery/Internal.hs index 229e5e24..bad950e7 100644 --- a/src/Servant/JQuery/Internal.hs +++ b/src/Servant/JQuery/Internal.hs @@ -214,4 +214,4 @@ instance (KnownSymbol path, HasJQ sublayout) req & reqUrl.path <>~ [Static str] & funcName %~ (str <>) - where str = symbolVal (Proxy :: Proxy path) + where str = map (\c -> if c == '.' then '_' else c) $ symbolVal (Proxy :: Proxy path) diff --git a/test/Servant/JQuerySpec.hs b/test/Servant/JQuerySpec.hs new file mode 100644 index 00000000..6d1add97 --- /dev/null +++ b/test/Servant/JQuerySpec.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE QuasiQuotes #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +module Servant.JQuerySpec where + +import Data.Either (isRight) +import Data.Proxy +import Language.ECMAScript3.Parser (parseFromString) +import Test.Hspec + +import Servant.API +import Servant.JQuery + +type TestAPI = [sitemap| +POST /simple String -> Bool +GET /has.extension Bool +|] + +spec :: Spec +spec = describe "Servant.JQuery" + generateJSSpec + +generateJSSpec :: Spec +generateJSSpec = describe "generateJS" $ + it "should always generate valid javascript" $ do + let (postSimple :<|> getHasExtension) = jquery (Proxy :: Proxy TestAPI) + parseFromString (generateJS postSimple) `shouldSatisfy` isRight + parseFromString (generateJS getHasExtension) `shouldSatisfy` isRight + diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 00000000..038e7c8e --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1,2 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} +