@hackage hspec-parsec0

Hspec expectations for testing Parsec parsers

hspec-parsec

License BSD3 Hackage

This package provides handy Hspec expectations for testing Parsec parsers.

Usage

Add hspec-parsec to your test suite's dependencies:

  build-depends:       base
                     , hspec
                     , hspec-parsec
                     , parsec

… write some tests:

import Test.Hspec
import Test.Hspec.Parsec
import Text.Parsec
import Text.Parsec.String (Parser)

main :: IO ()
main = hspec $ do
  describe "yamlBool" $ do
    let yamlBool' = parse yamlBool ""

    it "correctly parses \"True\"" $ do
      yamlBool' "True" `shouldParse` True

    it "doesn't parse \"yes\"" $ do
      yamlBool' `shouldFailOn` "yes"

yamlBool :: Parser Bool
yamlBool = 
        (choice (map string false) *> pure False)
    <|> (choice (map string true) *> pure True)
  where
    false = ["false", "False", "FALSE"]
    true = ["true", "True", "TRUE"]

… and run them:

$ stack test
hspec-parsec> test (suite: spec)


yamlBool
  correctly parses "True"
  doesn't parse "yes"

Finished in 0.0001 seconds
2 examples, 0 failures

hspec-parsec> Test suite spec passed

Thanks

… to Mark Karpov, whose package hspec-megaparsec much inspired hspec-parsec!