https://github.com/sjakobi/hspec-parsec
Hspec expectations for testing Parsec parsers
https://github.com/sjakobi/hspec-parsec
haskell hspec parsec parsing testing
Last synced: 2 months ago
JSON representation
Hspec expectations for testing Parsec parsers
- Host: GitHub
- URL: https://github.com/sjakobi/hspec-parsec
- Owner: sjakobi
- License: bsd-3-clause
- Created: 2019-08-23T23:26:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-24T01:03:57.000Z (over 5 years ago)
- Last Synced: 2024-04-26T15:22:51.461Z (about 1 year ago)
- Topics: haskell, hspec, parsec, parsing, testing
- Language: Haskell
- Size: 4.88 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hspec-parsec
[](http://opensource.org/licenses/BSD-3-Clause)
[](https://hackage.haskell.org/package/hspec-parsec)This package provides handy [Hspec](http://hspec.github.io/) expectations for testing
[Parsec](http://hackage.haskell.org/package/parsec) parsers.## Usage
Add `hspec-parsec` to your test suite's dependencies:
```
build-depends: base
, hspec
, hspec-parsec
, parsec
```… write some tests:
```haskell
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` Trueit "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:
```shell
$ stack test
hspec-parsec> test (suite: spec)yamlBool
correctly parses "True"
doesn't parse "yes"Finished in 0.0001 seconds
2 examples, 0 failureshspec-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! :)## Thanks
… to [Mark Karpov](https://github.com/mrkkrp), whose package
[`hspec-megaparsec`](https://hackage.haskell.org/package/hspec-megaparsec)
much inspired `hspec-parsec`!