Skip to content

Instantly share code, notes, and snippets.

@rcook
Last active March 30, 2020 05:46
Show Gist options
  • Save rcook/029e1a34e81da05fa3d6 to your computer and use it in GitHub Desktop.
Save rcook/029e1a34e81da05fa3d6 to your computer and use it in GitHub Desktop.
Example doctest in GitHub API client
#!/bin/bash
if [[ "$OSTYPE" =~ ^darwin ]]; then
READLINK=greadlink
else
READLINK=readlink
fi
SCRIPTPATH=$($READLINK -f $0)
SCRIPTDIR=$(dirname $SCRIPTPATH)
REPODIR=$(dirname $SCRIPTDIR)
pushd $REPODIR
stack exec doctest -- -isrc src/*.hs
-- file doctests.hs
import Test.DocTest
main = doctest ["-isrc", "src/Main.hs"]
The MIT License (MIT)
Copyright (c) 2016 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{-# OPTIONS_GHC -F -pgmF doctest-discover #-}
# Local packages, usually specified by relative directory name
packages:
- '.'
- location:
git: https://github.com/rcook/doctest-discover.git
commit: 1765720cd42cb875b689b44ba08c477d89e87439
-- | Gets port number from given URI
--
-- Examples:
-- >>> uriGetPort (fromJust $ parseURI "https://www.example.com/a/b") 1234
-- Just 1234
-- >>> uriGetPort (fromJust $ parseURI "https://www.example.com:4567/a/b") 1234
-- Just 4567
-- >>> uriGetPort nullURI 1234
-- Nothing
uriGetPort :: URI -> Word16 -> Maybe Word16
uriGetPort uri defaultPort = do
auth <- uriAuthority uri
return $ case uriPort auth of
"" -> defaultPort
p -> (Prelude.read $ Prelude.tail p) :: Word16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment