regex-1.1.0.2: Toolkit for regex-base

Safe Haskell | None
Language | Haskell2010

Text.RE.TestBench

Contents

- The Test Bench Tutorial
- The Test Bench
  - Constructing a MacrosEnv
  - Formatting Macros
  - Formatting Macros
- The Parsers
- The Match Type

Synopsis

- type MacroEnv = HashMap MacroID MacroDescriptor
- data MacroDescriptor = MacroDescriptor {
  - macroSource :: !RegexSource
  - macroSamples :: ![String]
  - macroCounterSamples :: ![String]
  - macroTestResults :: ![TestResult]
  - macroParser :: !(Maybe FunctionID)
  - macroDescription :: !String
  }
- newtype RegexSource = RegexSource {
  - _RegexSource :: String
  }
- data WithCaptures
  - = InclCaptures
  - | ExclCaptures
- data RegexType
- isTDFA :: RegexType -> Bool
- isPCRE :: RegexType -> Bool
- presentRegexType :: RegexType -> String
- mkMacros :: (Monad m, Functor m) => (String -> m r) -> RegexType -> WithCaptures -> MacroEnv -> m (Macros r)
- formatMacroTable :: RegexType -> MacroEnv -> String
- formatMacroSummary :: RegexType -> MacroEnv -> MacroID -> String
- formatMacroSources :: RegexType -> WithCaptures -> MacroEnv -> String
- formatMacroSource :: RegexType -> WithCaptures -> MacroEnv -> MacroID -> String
- mdRegexSource :: RegexType -> WithCaptures -> MacroEnv -> MacroDescriptor -> String
- testMacroEnv :: String -> RegexType -> MacroEnv -> IO Bool
- runTests :: (Eq a, Show a) => RegexType -> (String -> Maybe a) -> [(String, a)] -> MacroEnv -> MacroID -> MacroDescriptor -> MacroDescriptor
- runTests' :: (Eq a, Show a) => RegexType -> (Match String -> Maybe a) -> [(String, a)] -> MacroEnv -> MacroID -> MacroDescriptor -> MacroDescriptor
- module Text.RE.TestBench.Parsers
- data Match a

# The Test Bench Tutorial

This API module provides a test bench for developing, documenting and testing regex RE macros.

See the tutorials at http://re-tutorial-testbench.regex.uk

# The Test Bench

type MacroEnv = HashMap MacroID MacroDescriptor Source #

each macro can reference others, the whole environment being required for each macro, so we use a Lazy HashMap

data MacroDescriptor Source #

describes a macro, giving the text of the RE and a summary description

Constructors

MacroDescriptor |

Fields

- macroSource :: !RegexSource

  the RE

- macroSamples :: ![String]

  some sample matches

- macroCounterSamples :: ![String]

  some sample non-matches

- macroTestResults :: ![TestResult]

  validation test results

- macroParser :: !(Maybe FunctionID)

  WA, the parser function

- macroDescription :: !String

  summary comment

#### Instances

Instances details

Show MacroDescriptor Source # |
Instance details Defined in Text.RE.ZeInternals.TestBench Methods showsPrec :: Int -> MacroDescriptor -> ShowS Source # show :: MacroDescriptor -> String Source # showList :: [MacroDescriptor] -> ShowS Source #

newtype RegexSource Source #

a RE that should work for POSIX and PCRE with open brackets ('(') represented as follows: ( mere symbol (?: used for grouping only, not for captures (}: used for captures only, not for grouping (]: used for captures and grouping ( do not modify

Constructors

RegexSource |

Fields

- _RegexSource :: String

#### Instances

Instances details

IsString RegexSource Source # |
Instance details Defined in Text.RE.ZeInternals.TestBench Methods fromString :: String -> RegexSource Source #
Show RegexSource Source # |
Instance details Defined in Text.RE.ZeInternals.TestBench Methods showsPrec :: Int -> RegexSource -> ShowS Source # show :: RegexSource -> String Source # showList :: [RegexSource] -> ShowS Source #

data WithCaptures Source #

do we need the captures in the RE or would they be stripped out where possible

Constructors

InclCaptures | include all captures
ExclCaptures | remove captures where possible

#### Instances

Instances details

Show WithCaptures Source # |
Instance details Defined in Text.RE.ZeInternals.TestBench Methods showsPrec :: Int -> WithCaptures -> ShowS Source # show :: WithCaptures -> String Source # showList :: [WithCaptures] -> ShowS Source #
Eq WithCaptures Source # |
Instance details Defined in Text.RE.ZeInternals.TestBench Methods (==) :: WithCaptures -> WithCaptures -> Bool Source # (/=) :: WithCaptures -> WithCaptures -> Bool Source #
Ord WithCaptures Source # |

Instance details

Defined in Text.RE.ZeInternals.TestBench

Methods

compare :: WithCaptures -> WithCaptures -> Ordering Source #

(<) :: WithCaptures -> WithCaptures -> Bool Source #

(<=) :: WithCaptures -> WithCaptures -> Bool Source #

(>) :: WithCaptures -> WithCaptures -> Bool Source #

(>=) :: WithCaptures -> WithCaptures -> Bool Source #

max :: WithCaptures -> WithCaptures -> WithCaptures Source #

min :: WithCaptures -> WithCaptures -> WithCaptures Source #

data RegexType Source #

what flavour of regex are we dealing with

#### Instances

Instances details

Show RegexType Source # |
Instance details Defined in Text.RE.ZeInternals.TestBench Methods showsPrec :: Int -> RegexType -> ShowS Source # show :: RegexType -> String Source # showList :: [RegexType] -> ShowS Source #

isTDFA :: RegexType -> Bool Source #

test RegexType for TDFA/PCREness

isPCRE :: RegexType -> Bool Source #

test RegexType for TDFA/PCREness

presentRegexType :: RegexType -> String Source #

## Constructing a MacrosEnv

mkMacros :: (Monad m, Functor m) => (String -> m r) -> RegexType -> WithCaptures -> MacroEnv -> m (Macros r) Source #

construct a macro table suitable for use with the RE compilers

## Formatting Macros

formatMacroTable :: RegexType -> MacroEnv -> String Source #

format a macros table as a markdown table

formatMacroSummary :: RegexType -> MacroEnv -> MacroID -> String Source #

generate a plain text summary of a macro

formatMacroSources :: RegexType -> WithCaptures -> MacroEnv -> String Source #

list the source REs for each macro in plain text

formatMacroSource :: RegexType -> WithCaptures -> MacroEnv -> MacroID -> String Source #

list the source of a single macro in plain text

mdRegexSource :: RegexType -> WithCaptures -> MacroEnv -> MacroDescriptor -> String Source #

## Formatting Macros

testMacroEnv :: String -> RegexType -> MacroEnv -> IO Bool Source #

test that a MacroEnv is passing all of its built-in tests

runTests :: (Eq a, Show a) => RegexType -> (String -> Maybe a) -> [(String, a)] -> MacroEnv -> MacroID -> MacroDescriptor -> MacroDescriptor Source #

runTests' :: (Eq a, Show a) => RegexType -> (Match String -> Maybe a) -> [(String, a)] -> MacroEnv -> MacroID -> MacroDescriptor -> MacroDescriptor Source #

# The Parsers

module Text.RE.TestBench.Parsers

# The Match Type

data Match a Source #

the result of matching a RE to a text once (with `?=~`), retaining the text that was matched against

#### Instances

Instances details

Functor Match Source # |
Instance details Defined in Text.RE.ZeInternals.Types.Match Methods fmap :: (a -> b) -> Match a -> Match b Source # (<$) :: a -> Match b -> Match a Source #
(RegexContext regex source (AllTextSubmatches (Array Int) (source, (Int, Int))), RegexLike regex source, RegexFix regex source) => RegexContext regex source (Match source) Source # | this instance hooks `Match` into regex-base: regex consumers need not worry about any of this
Instance details Defined in Text.RE.ZeInternals.Types.Match Methods match :: regex -> source -> Match source Source # matchM :: MonadFail m => regex -> source -> m (Match source) Source #
Show a => Show (Match a) Source # |
Instance details Defined in Text.RE.ZeInternals.Types.Match Methods showsPrec :: Int -> Match a -> ShowS Source # show :: Match a -> String Source # showList :: [Match a] -> ShowS Source #
Eq a => Eq (Match a) Source # |
Instance details Defined in Text.RE.ZeInternals.Types.Match Methods (==) :: Match a -> Match a -> Bool Source # (/=) :: Match a -> Match a -> Bool Source #