HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulehspec-megaparsec-2.2.1GHC2021

Test.Hspec.Megaparsec

Utility functions for testing Megaparsec parsers with Hspec.

Contents
  1. Basic expectations
  2. Testing of error messages
  3. Incremental parsing
  4. Re-exports
Synopsis

Basic expectations

Testing of error messages

valueshouldFailWithM
  1. :: (HasCallStack, ShowErrorComponent e, Stream s, VisualStream s, TraversableStream s, Show a, Eq e)
  2. => Either (ParseErrorBundle s e) a

    The result of parsing

  3. -> [ParseError s e]

    Expected parse errors, the argument is a normal linked list (as opposed to the more correct NonEmpty list) as a syntactical convenience for the user, passing empty list here will result in an error

  4. -> Expectation

Similar to shouldFailWith, but allows us to check parsers that can report more than one parse error at a time.

Incremental parsing

valuefailsLeaving
  1. :: (HasCallStack, Show a, Eq s, Show s)
  2. => (State s e, Either (ParseErrorBundle s e) a)

    Parser that takes stream and produces result along with actual state information

  3. -> s

    Part of input that should be left unconsumed

  4. -> Expectation

Check that a parser fails and leaves a certain part of input unconsumed. Use it with functions like runParser' and runParserT' that support incremental parsing.

runParser' (many (char 'x') <* eof) (initialState "xxa")
  `failsLeaving` "a"

See also: initialState.

valuesucceedsLeaving
  1. :: (HasCallStack, Show a, Eq s, Show s, ShowErrorComponent e, Stream s, VisualStream s, TraversableStream s)
  2. => (State s e, Either (ParseErrorBundle s e) a)

    Parser that takes stream and produces result along with actual state information

  3. -> s

    Part of input that should be left unconsumed

  4. -> Expectation

Check that a parser succeeds and leaves certain part of input unconsumed. Use it with functions like runParser' and runParserT' that support incremental parsing.

runParser' (many (char 'x')) (initialState "xxa")
  `succeedsLeaving` "a"

See also: initialState.

Re-exports

valueeeof :: ET s

Construct an “expected end of input” error component.

valueelabel :: String -> ET s

Construct an “expected label” error component. Do not use with empty strings.

valueetok :: Token s -> ET s

Construct an “expected token” error component.

valueueof :: ET s

Construct an “unexpected end of input” error component.

valueulabel :: String -> ET s

Construct an “unexpected label” error component. Do not use with empty strings (for empty strings it's bottom).

valueutok :: Token s -> ET s

Construct an “unexpected token” error component.

newtypenewtype EF e

Auxiliary type for construction of fancy parse errors.

Instances7Eq, Data, Ord, Generic, Semigroup, Monoid, …
datadata ET s

Auxiliary type for construction of trivial parse errors.

Instances7Eq, Data, Ord, Generic, Semigroup, Monoid, …