HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehspec-megaparsec-2.2.1GHC2021

Test.Hspec.Megaparsec

Utility functions for testing Megaparsec parsers with Hspec.

  • 2 types
  • 21 values

Basic expectations

4 declarations

Testing of error messages

2 declarations
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

4 declarations
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.

valueinitialState :: s -> State s e
#

Given input for parsing, construct initial state for parser.

Re-exports

13 declarations
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, …
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.