Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkkrp committed Dec 25, 2015
1 parent 961fa8c commit dd2b4ea
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ script:
esac
- cabal build
- cabal test --show-details=always
--test-option=--threads=2
--test-option=--maximum-generated-tests=1000
- cabal sdist
- cabal haddock | grep "100%" | wc -l | grep "1"

Expand Down
21 changes: 13 additions & 8 deletions slug.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ test-suite tests
ghc-options: -Wall -Werror
else
ghc-options: -O2 -Wall
build-depends: base >= 4.6 && < 5
, slug >= 0.1
, QuickCheck >= 2.4 && < 3
, test-framework >= 0.6 && < 1
, test-framework-quickcheck2 >= 0.3 && < 0.4
default-language: Haskell2010
default-extensions: OverloadedStrings
build-depends: QuickCheck >= 2.4 && < 3
, HUnit >= 1.2 && < 1.4
, base >= 4.6 && < 5
, path-pieces >= 0.1.5
, slug >= 0.1
, test-framework >= 0.6 && < 1
, test-framework-hunit >= 0.2 && < 0.4
, test-framework-quickcheck2 >= 0.3 && < 0.4
, text >= 1.0
default-language: Haskell2010

source-repository head
type: git
location: https://github.com/mrkkrp/slug.git
type: git
location: https://github.com/mrkkrp/slug.git
55 changes: 53 additions & 2 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,60 @@
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.

{-# OPTIONS -fno-warn-orphans #-}

module Main (main) where

import Test.Framework (defaultMain)
import Control.Monad ((>=>))
import Data.Char (isAlphaNum)
import Data.Maybe (isJust)
import Data.Text (Text)
import Test.Framework
import Test.Framework.Providers.HUnit (testCase)
import Test.Framework.Providers.QuickCheck2 (testProperty)
import Test.HUnit hiding (Test, path)
import Test.QuickCheck
import Web.PathPieces
import Web.Slug
import qualified Data.Text as T

main :: IO ()
main = defaultMain []
main = defaultMain [tests]

tests :: Test
tests = testGroup "Slug properties"
[ testProperty "Slug of slug is the slug" prop_changeStops
, testProperty "Alpha-numeric chars are necessary and sufficient"
prop_needAlphaNum
, testProperty "Path pieces accept correct slugs" prop_pathPiece
, testCase "Removal of apostrophe" prop_apostropheRemoval
, testCase "Path pieces ignore case of slugs" prop_pathPieceCase
]

instance Arbitrary Text where
arbitrary = T.pack <$> arbitrary

prop_changeStops :: Text -> Property
prop_changeStops x = v (f x) === v (g x)
where f = mkSlug
g = mkSlug >=> mkSlug . unSlug
v = either (Left . show) Right

prop_needAlphaNum :: Text -> Property
prop_needAlphaNum x = hasAlphaNum x ==> isJust (mkSlug x)
where hasAlphaNum = isJust . T.find isAlphaNum

prop_pathPiece :: Text -> Property
prop_pathPiece x =
case mkSlug x of
Nothing -> property True
Just slug -> fromPathPiece (unSlug slug) === Just slug

prop_apostropheRemoval :: Assertion
prop_apostropheRemoval = unSlug <$> mkSlug text @?= Just slug
where text = "That's what I thought about doin' that stuff!"
slug = "thats-what-i-thought-about-doin-that-stuff"

prop_pathPieceCase :: Assertion
prop_pathPieceCase = fromPathPiece text @?= mkSlug text
where text = "thiS-Строка-hAs-коМбиНацию-of-DiffErent-Cases" :: Text

0 comments on commit dd2b4ea

Please sign in to comment.