hspec-parsec: Hspec expectations for testing Parsec parsers

[ bsd3, library, parsing, testing ] [ Propose Tags ]

Modules

[Index] [Quick Jump]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0
Dependencies base (>=4.9 && <5), hspec-expectations (<0.9), parsec (<3.2) [details]
License BSD-3-Clause
Copyright Copyright (c) 2019 Simon Jakobi
Author Simon Jakobi, Mark Karpov
Maintainer simon.jakobi@gmail.com
Revised Revision 1 made by sjakobi at 2019-08-24T00:09:11Z
Category Testing, Parsing
Home page https://github.com/sjakobi/hspec-parsec#readme
Bug tracker https://github.com/sjakobi/hspec-parsec/issues
Source repo head: git clone https://github.com/sjakobi/hspec-parsec
Uploaded by sjakobi at 2019-08-23T23:31:31Z
Distributions LTSHaskell:0, NixOS:0, Stackage:0
Downloads 822 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-08-24 [all 1 reports]

Readme for hspec-parsec-0

[back to package description]

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!