hspec-parsec: Hspec expectations for testing Parsec parsers

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

Warnings:


[Skip to ReadMe]

Properties

Versions0, 0
Change logNone available
Dependenciesbase (>=4.7 && <5), hspec-expectations (<0.9), parsec (<3.2) [details]
LicenseBSD-3-Clause
CopyrightCopyright (c) 2019 Simon Jakobi
AuthorSimon Jakobi, Mark Karpov
Maintainersimon.jakobi@gmail.com
CategoryTesting, Parsing
Home pagehttps://github.com/sjakobi/hspec-parsec#readme
Bug trackerhttps://github.com/sjakobi/hspec-parsec/issues
Source repositoryhead: git clone https://github.com/sjakobi/hspec-parsec
UploadedFri Aug 23 23:29:48 UTC 2019 by sjakobi

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees


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!