Cucumberex.StepDefinition.Expression (cucumberex v0.2.1)

Copy Markdown View Source

Compile Cucumber Expressions and plain Regex patterns to Elixir regexes.

Cucumber Expression syntax: {int} → -?\d+ {float} → -?\d*.\d+ {string} → "..." or '...' {word} → [^\s]+ {paramtype} → looked up in ParameterType registry (optional) → optional group a/b → alternation

Summary

Functions

Compile a Cucumber Expression string or Regex to an internal match pattern.

Match step text against a pattern, returning %{args: [...]} or nil.

Types

match()

@type match() :: %{args: list(), param_types: [Cucumberex.ParameterType.t()]}

Functions

compile(pattern, param_type_registry \\ Cucumberex.ParameterType.Registry)

Compile a Cucumber Expression string or Regex to an internal match pattern.

The param_type_registry pid is required for Cucumber Expressions containing {custom_type} parameters; plain strings and regexes don't need it.

Examples

iex> {:regex, _} = Cucumberex.StepDefinition.Expression.compile(~r/^foo$/)

iex> {kind, _} = Cucumberex.StepDefinition.Expression.compile("^raw regex$", nil)
iex> kind
:regex

match(pattern, text, registry \\ Cucumberex.ParameterType.Registry)

Match step text against a pattern, returning %{args: [...]} or nil.

Examples

iex> Cucumberex.StepDefinition.Expression.match(~r/^hello (\w+)$/, "hello world", nil)
%{args: ["world"], param_types: []}

iex> Cucumberex.StepDefinition.Expression.match(~r/^nope$/, "hello", nil)
nil