Skip to content

Instantly share code, notes, and snippets.

@algas
Last active December 11, 2017 02:03
Show Gist options
  • Select an option

  • Save algas/0ec303769e09a8c9188b83a3d7a8990c to your computer and use it in GitHub Desktop.

Select an option

Save algas/0ec303769e09a8c9188b83a3d7a8990c to your computer and use it in GitHub Desktop.

Revisions

  1. algas revised this gist Dec 11, 2017. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion hspec-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ homepage: https://github.com/{{github-username}}{{^github-username}}g
    license: BSD3
    author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
    maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
    copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2017{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
    copyright: {{year}}{{^year}}2017{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
    category: {{category}}{{^category}}Web{{/category}}
    extra-source-files:
    - README.md
    2 changes: 1 addition & 1 deletion servant-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ homepage: https://github.com/{{github-username}}{{^github-username}}g
    license: BSD3
    author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
    maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
    copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2017{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
    copyright: {{year}}{{^year}}2017{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
    category: {{category}}{{^category}}Web{{/category}}
    extra-source-files:
    - README.md
  2. algas revised this gist Sep 23, 2017. 2 changed files with 28 additions and 73 deletions.
    99 changes: 27 additions & 72 deletions hspec-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -18,11 +18,6 @@ dependencies:
    library:
    source-dirs:
    - src
    dependencies:
    - aeson
    - servant-server
    - wai
    - warp

    executables:
    {{name}}:
    @@ -41,9 +36,7 @@ tests:
    dependencies:
    - {{name}}
    - hspec
    - hspec-wai
    - hspec-wai-json
    - aeson
    - QuickCheck
    ghc-options: -threaded -rtsopts -with-rtsopts=-N

    github: {{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}
    @@ -65,83 +58,42 @@ main = defaultMain
    {-# START_FILE test/Spec.hs #-}
    {-# OPTIONS_GHC -F -pgmF hspec-discover #-}

    {-# START_FILE test/LibSpec.hs #-}
    {-# LANGUAGE QuasiQuotes #-}
    {-# LANGUAGE OverloadedStrings #-}
    module LibSpec (
    main
    , spec
    ) where
    {-# START_FILE test/Data/String/StripSpec.hs #-}
    module Data.String.StripSpec (main, spec) where

    import Lib (app)
    import Test.Hspec
    import Test.Hspec.Wai
    import Test.Hspec.Wai.JSON
    import Test.QuickCheck

    import Data.String.Strip

    -- `main` is here so that this module can be run from GHCi on its own. It is
    -- not needed for automatic spec discovery.
    main :: IO ()
    main = hspec spec

    spec :: Spec
    spec = with (return app) $ do
    describe "GET /users" $ do
    it "responds with 200" $ do
    get "/users" `shouldRespondWith` 200
    it "responds with [User]" $ do
    let users = "[{\"userId\":1,\"userFirstName\":\"Isaac\",\"userLastName\":\"Newton\"},{\"userId\":2,\"userFirstName\":\"Albert\",\"userLastName\":\"Einstein\"}]"
    get "/users" `shouldRespondWith` users

    {-# START_FILE src/Lib.hs #-}
    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE TemplateHaskell #-}
    {-# LANGUAGE TypeOperators #-}
    module Lib
    ( startApp
    , app
    ) where

    import Data.Aeson
    import Data.Aeson.TH
    import Network.Wai
    import Network.Wai.Handler.Warp
    import Servant

    data User = User
    { userId :: Int
    , userFirstName :: String
    , userLastName :: String
    } deriving (Eq, Show)

    $(deriveJSON defaultOptions ''User)

    type API = "users" :> Get '[JSON] [User]

    startApp :: IO ()
    startApp = run 8080 app

    app :: Application
    app = serve api server

    api :: Proxy API
    api = Proxy

    server :: Server API
    server = return users

    users :: [User]
    users = [ User 1 "Isaac" "Newton"
    , User 2 "Albert" "Einstein"
    ]
    spec = do
    describe "strip" $ do
    it "removes leading and trailing whitespace" $ do
    strip "\t foo bar\n" `shouldBe` "foo bar"
    it "is idempotent" $ property $
    \str -> strip str === strip (strip str)

    {-# START_FILE src/Data/String/Strip.hs #-}
    module Data.String.Strip (strip) where

    import Data.Char

    strip :: String -> String
    strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse

    {-# START_FILE app/Main.hs #-}
    module Main where

    import Lib
    import Data.String.Strip

    main :: IO ()
    main = startApp

    {-# START_FILE README.md #-}
    # {{name}}
    main = interact strip

    {-# START_FILE LICENSE #-}
    Copyright {{author-name}}{{^author-name}}Author name here{{/author-name}} (c) {{year}}{{^year}}2017{{/year}}
    @@ -174,3 +126,6 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    {-# START_FILE README.md #-}
    # {{name}}
    2 changes: 1 addition & 1 deletion servant-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ library:
    - warp

    executables:
    {{name}}-exe:
    {{name}}:
    source-dirs:
    - app
    main: Main.hs
  3. algas revised this gist Sep 23, 2017. 1 changed file with 82 additions and 28 deletions.
    110 changes: 82 additions & 28 deletions hspec-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,11 @@ dependencies:
    library:
    source-dirs:
    - src
    dependencies:
    - aeson
    - servant-server
    - wai
    - warp

    executables:
    {{name}}:
    @@ -36,54 +41,107 @@ tests:
    dependencies:
    - {{name}}
    - hspec
    - QuickCheck
    - hspec-wai
    - hspec-wai-json
    - aeson
    ghc-options: -threaded -rtsopts -with-rtsopts=-N

    github: {{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}

    {-# START_FILE .gitignore #-}
    *.hi
    *.o
    *.swp
    *.tag
    *~
    .stack-work/
    dist/
    *.cabal

    {-# START_FILE Setup.hs #-}
    import Distribution.Simple
    main = defaultMain

    {-# START_FILE test/Spec.hs #-}
    {-# OPTIONS_GHC -F -pgmF hspec-discover #-}

    {-# START_FILE test/Data/String/StripSpec.hs #-}
    module Data.String.StripSpec (main, spec) where
    {-# START_FILE test/LibSpec.hs #-}
    {-# LANGUAGE QuasiQuotes #-}
    {-# LANGUAGE OverloadedStrings #-}
    module LibSpec (
    main
    , spec
    ) where

    import Lib (app)
    import Test.Hspec
    import Test.QuickCheck

    import Data.String.Strip
    import Test.Hspec.Wai
    import Test.Hspec.Wai.JSON

    -- `main` is here so that this module can be run from GHCi on its own. It is
    -- not needed for automatic spec discovery.
    main :: IO ()
    main = hspec spec

    spec :: Spec
    spec = do
    describe "strip" $ do
    it "removes leading and trailing whitespace" $ do
    strip "\t foo bar\n" `shouldBe` "foo bar"
    it "is idempotent" $ property $
    \str -> strip str === strip (strip str)

    {-# START_FILE src/Data/String/Strip.hs #-}
    module Data.String.Strip (strip) where

    import Data.Char

    strip :: String -> String
    strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse
    spec = with (return app) $ do
    describe "GET /users" $ do
    it "responds with 200" $ do
    get "/users" `shouldRespondWith` 200
    it "responds with [User]" $ do
    let users = "[{\"userId\":1,\"userFirstName\":\"Isaac\",\"userLastName\":\"Newton\"},{\"userId\":2,\"userFirstName\":\"Albert\",\"userLastName\":\"Einstein\"}]"
    get "/users" `shouldRespondWith` users

    {-# START_FILE src/Lib.hs #-}
    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE TemplateHaskell #-}
    {-# LANGUAGE TypeOperators #-}
    module Lib
    ( startApp
    , app
    ) where

    import Data.Aeson
    import Data.Aeson.TH
    import Network.Wai
    import Network.Wai.Handler.Warp
    import Servant

    data User = User
    { userId :: Int
    , userFirstName :: String
    , userLastName :: String
    } deriving (Eq, Show)

    $(deriveJSON defaultOptions ''User)

    type API = "users" :> Get '[JSON] [User]

    startApp :: IO ()
    startApp = run 8080 app

    app :: Application
    app = serve api server

    api :: Proxy API
    api = Proxy

    server :: Server API
    server = return users

    users :: [User]
    users = [ User 1 "Isaac" "Newton"
    , User 2 "Albert" "Einstein"
    ]

    {-# START_FILE app/Main.hs #-}
    module Main where

    import Data.String.Strip
    import Lib

    main :: IO ()
    main = interact strip
    main = startApp

    {-# START_FILE README.md #-}
    # {{name}}

    {-# START_FILE LICENSE #-}
    Copyright {{author-name}}{{^author-name}}Author name here{{/author-name}} (c) {{year}}{{^year}}2017{{/year}}
    @@ -116,7 +174,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    {-# START_FILE README.md #-}
    # {{name}}

    add description of {{name}} here
  4. algas revised this gist Sep 23, 2017. 1 changed file with 122 additions and 0 deletions.
    122 changes: 122 additions & 0 deletions hspec-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,122 @@
    {-# START_FILE package.yaml #-}
    name: {{name}}
    version: 0.1.0.0
    #synopsis:
    #description:
    homepage: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}#readme
    license: BSD3
    author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
    maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
    copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2017{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
    category: {{category}}{{^category}}Web{{/category}}
    extra-source-files:
    - README.md

    dependencies:
    - base >= 4.7 && < 5

    library:
    source-dirs:
    - src

    executables:
    {{name}}:
    source-dirs:
    - app
    main: Main.hs
    ghc-options: -threaded -rtsopts -with-rtsopts=-N
    dependencies:
    - {{name}}

    tests:
    {{name}}-test:
    source-dirs:
    - test
    main: Spec.hs
    dependencies:
    - {{name}}
    - hspec
    - QuickCheck
    ghc-options: -threaded -rtsopts -with-rtsopts=-N

    github: {{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}

    {-# START_FILE Setup.hs #-}
    import Distribution.Simple
    main = defaultMain

    {-# START_FILE test/Spec.hs #-}
    {-# OPTIONS_GHC -F -pgmF hspec-discover #-}

    {-# START_FILE test/Data/String/StripSpec.hs #-}
    module Data.String.StripSpec (main, spec) where

    import Test.Hspec
    import Test.QuickCheck

    import Data.String.Strip

    -- `main` is here so that this module can be run from GHCi on its own. It is
    -- not needed for automatic spec discovery.
    main :: IO ()
    main = hspec spec

    spec :: Spec
    spec = do
    describe "strip" $ do
    it "removes leading and trailing whitespace" $ do
    strip "\t foo bar\n" `shouldBe` "foo bar"
    it "is idempotent" $ property $
    \str -> strip str === strip (strip str)

    {-# START_FILE src/Data/String/Strip.hs #-}
    module Data.String.Strip (strip) where

    import Data.Char

    strip :: String -> String
    strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse

    {-# START_FILE app/Main.hs #-}
    module Main where

    import Data.String.Strip

    main :: IO ()
    main = interact strip

    {-# START_FILE LICENSE #-}
    Copyright {{author-name}}{{^author-name}}Author name here{{/author-name}} (c) {{year}}{{^year}}2017{{/year}}

    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
    copyright notice, this list of conditions and the following
    disclaimer in the documentation and/or other materials provided
    with the distribution.

    * Neither the name of {{author-name}}{{^author-name}}Author name here{{/author-name}} nor the names of other
    contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    {-# START_FILE README.md #-}
    # {{name}}

    add description of {{name}} here
  5. algas revised this gist Sep 23, 2017. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions servant-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,6 @@ dependencies:
    library:
    source-dirs:
    - src
    exposed-modules:
    - Lib
    dependencies:
    - aeson
    - servant-server
    @@ -65,9 +63,15 @@ import Distribution.Simple
    main = defaultMain

    {-# START_FILE test/Spec.hs #-}
    {-# OPTIONS_GHC -F -pgmF hspec-discover #-}

    {-# START_FILE test/LibSpec.hs #-}
    {-# LANGUAGE QuasiQuotes #-}
    {-# LANGUAGE OverloadedStrings #-}
    module Main (main) where
    module LibSpec (
    main
    , spec
    ) where

    import Lib (app)
    import Test.Hspec
  6. algas created this gist Sep 23, 2017.
    172 changes: 172 additions & 0 deletions servant-hpack.hsfiles
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,172 @@
    {-# START_FILE package.yaml #-}
    name: {{name}}
    version: 0.1.0.0
    #synopsis:
    #description:
    homepage: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}#readme
    license: BSD3
    author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
    maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
    copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2017{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
    category: {{category}}{{^category}}Web{{/category}}
    extra-source-files:
    - README.md

    dependencies:
    - base >= 4.7 && < 5

    library:
    source-dirs:
    - src
    exposed-modules:
    - Lib
    dependencies:
    - aeson
    - servant-server
    - wai
    - warp

    executables:
    {{name}}-exe:
    source-dirs:
    - app
    main: Main.hs
    ghc-options: -threaded -rtsopts -with-rtsopts=-N
    dependencies:
    - {{name}}

    tests:
    {{name}}-test:
    source-dirs:
    - test
    main: Spec.hs
    dependencies:
    - {{name}}
    - hspec
    - hspec-wai
    - hspec-wai-json
    - aeson
    ghc-options: -threaded -rtsopts -with-rtsopts=-N

    github: {{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}

    {-# START_FILE .gitignore #-}
    *.hi
    *.o
    *.swp
    *.tag
    *~
    .stack-work/
    dist/
    *.cabal

    {-# START_FILE Setup.hs #-}
    import Distribution.Simple
    main = defaultMain

    {-# START_FILE test/Spec.hs #-}
    {-# LANGUAGE QuasiQuotes #-}
    {-# LANGUAGE OverloadedStrings #-}
    module Main (main) where

    import Lib (app)
    import Test.Hspec
    import Test.Hspec.Wai
    import Test.Hspec.Wai.JSON

    main :: IO ()
    main = hspec spec

    spec :: Spec
    spec = with (return app) $ do
    describe "GET /users" $ do
    it "responds with 200" $ do
    get "/users" `shouldRespondWith` 200
    it "responds with [User]" $ do
    let users = "[{\"userId\":1,\"userFirstName\":\"Isaac\",\"userLastName\":\"Newton\"},{\"userId\":2,\"userFirstName\":\"Albert\",\"userLastName\":\"Einstein\"}]"
    get "/users" `shouldRespondWith` users

    {-# START_FILE src/Lib.hs #-}
    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE TemplateHaskell #-}
    {-# LANGUAGE TypeOperators #-}
    module Lib
    ( startApp
    , app
    ) where

    import Data.Aeson
    import Data.Aeson.TH
    import Network.Wai
    import Network.Wai.Handler.Warp
    import Servant

    data User = User
    { userId :: Int
    , userFirstName :: String
    , userLastName :: String
    } deriving (Eq, Show)

    $(deriveJSON defaultOptions ''User)

    type API = "users" :> Get '[JSON] [User]

    startApp :: IO ()
    startApp = run 8080 app

    app :: Application
    app = serve api server

    api :: Proxy API
    api = Proxy

    server :: Server API
    server = return users

    users :: [User]
    users = [ User 1 "Isaac" "Newton"
    , User 2 "Albert" "Einstein"
    ]

    {-# START_FILE app/Main.hs #-}
    module Main where

    import Lib

    main :: IO ()
    main = startApp

    {-# START_FILE README.md #-}
    # {{name}}

    {-# START_FILE LICENSE #-}
    Copyright {{author-name}}{{^author-name}}Author name here{{/author-name}} (c) {{year}}{{^year}}2017{{/year}}

    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
    copyright notice, this list of conditions and the following
    disclaimer in the documentation and/or other materials provided
    with the distribution.

    * Neither the name of {{author-name}}{{^author-name}}Author name here{{/author-name}} nor the names of other
    contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.