parsable-test-0.1.0.0: Test functions for the parsable package
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Parsable

Description

Test functions for Parsable and Printable.

Synopsis

Partial parses

data ParseCoverage Source #

If a parse succeeds for the beginning of the input, but then fails, we choose the PartialParse constructor. If the entire parse was successful, we choose CompleteParse.

This is mostly useful for testing parsers where we need to test them individually (must end with CompleteParse) and also composed together (individual parsers may end with PartialParse if they do not conclude the larger parse).

QuickCheck

parsableQuickCheck :: forall proxy a. (Parsable a Identity () String, Printable a, Arbitrary a, Eq a, Show a, Typeable a) => proxy a -> STM TestTree Source #

QuickCheck tests for any Parsable type. Currently this only checks parsableProp.

parsableProp :: forall a. (Parsable a Identity () String, Printable a, Eq a, Show a) => TChan ParseError -> a -> Property Source #

QuickCheck property that verifies the "round-trip law" of any type which is both Parsable and Printable.

Generators

wordGen :: [Char -> Bool] -> [Char -> Bool] -> Gen String Source #

Generator which takes two lists of predicates which specify valid characters.

  • The first list is specifically for characters that start the string.
  • The second list is for any subsequent characters.

This generator always creates a non-empty string.

HUnit

parsableHUnit :: forall proxy a. (Parsable a Identity () String, Printable a, Show a) => proxy a -> String -> TestTree Source #

HUnit tests for a string which should be parsed as a Parsable

Currently this checks:

printableHUnit :: forall a. (Parsable a Identity () String, Printable a, Show a, Eq a) => a -> TestTree Source #

HUnit tests for a Parsable/Printable value

Currently this checks:

parsableAssertion :: forall proxy a. (Parsable a Identity () String, Printable a, Show a) => proxy a -> String -> Assertion Source #

The string is parsed as a Parsable/Printable value, which is then converted back to a string. This HUnit assertion verifies that the resulting string is the same as the original.

printableAssertion :: forall a. (Parsable a Identity () String, Printable a, Show a, Eq a) => a -> Assertion Source #

The Parsable/Printable value is converted to a string, which is then parsed. This HUnit assertion verifies that the parse result is the same as the original value.

Generic functions

runCheckParsable :: Parsable a Identity () String => String -> Either ParseError (ParseCoverage, a) Source #

Parses a string as the given Parsable value

checkParsable :: forall a s u m. (Stream s m Char, Parsable a m u s) => ParsecT s u m (ParseCoverage, a) Source #

Convenience function that runs checkCoverage on a Parsable parser.

checkCoverage :: Stream s m Char => ParsecT s u m a -> ParsecT s u m (ParseCoverage, a) Source #

Run the specified parser, then return CompleteParse if we are at eof, otherwise PartialParse.

Re-exports

data ParseError #

The abstract data type ParseError represents parse errors. It provides the source position (SourcePos) of the error and a list of error messages (Message). A ParseError can be returned by the function parse. ParseError is an instance of the Show and Eq classes.

Instances

Instances details
Show ParseError 
Instance details

Defined in Text.Parsec.Error

Eq ParseError 
Instance details

Defined in Text.Parsec.Error

module Data.Void