Hspec expectations for testing Parsec parsers

License: BSD-3-Clause

Language: Haskell

Keywords: haskell, hspec, parsec, parsing, testing


License BSD3 Hackage

This package provides handy Hspec expectations for testing Parsec parsers.


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)
    false = ["false", "False", "FALSE"]
    true = ["true", "True", "TRUE"]

… and run them:

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

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

Finished in 0.0001 seconds
2 examples, 0 failures

hspec-parsec> Test suite spec passed

Development status and contributing

This package is currently very limited. If you need more functionality or want to contribute in some other way, you're welcome to open an issue or make a PR! :)


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

Project Statistics

Sourcerank 3
Repository Size 4.88 KB
Stars 0
Forks 0
Watchers 1
Open issues 0
Dependencies 7
Contributors 1
Tags 2
Last updated
Last pushed

Top Contributors See all

Simon Jakobi

Packages Referencing this Repo

[Index] [Quick Jump] Note: This package has metadata revisions in the cabal description newer ...
Latest release 0-r1 - Published

Recent Tags See all

0-r1 August 24, 2019
0 August 23, 2019

Something wrong with this page? Make a suggestion

Last synced: 2019-08-24 07:17:00 UTC

Login to resync this repository