Giter Club home page Giter Club logo

hspec-parsec's Introduction

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

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, whose package hspec-megaparsec much inspired hspec-parsec!

hspec-parsec's People

Contributors

sjakobi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.