phrase

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package phrase turns `# @step` phrases such as `a user named {name} exists` into anchored regular expressions whose capture groups map to variables.

Index

Constants

View Source
const MaxParams = 6

MaxParams is the most parameters a phrase may declare.

Variables

View Source
var Builtin = []BuiltinStep{
	{"environment", `^the environment is "([^"]*)"$`, []string{`the environment is "{x}"`}},
	{"variable", `^the variable "([^"]+)" is "([^"]*)"$`, []string{`the variable "{x}" is "{y}"`}},
	{"variables", `^the variables:$`, []string{"the variables:"}},
	{"run", `^I run "([^"]*)"$`, []string{`I run "{x}"`}},
	{"run-with", `^I run "([^"]*)" with:$`, []string{`I run "{x}" with:`}},
	{"run-file", `^I run the file "([^"]*)"$`, []string{`I run the file "{x}"`}},
	{"status", `^the response status is (\d+)$`, []string{"the response status is {#}"}},
	{"status-not", `^the response status is not (\d+)$`, []string{"the response status is not {#}"}},
	{"status-class", `^the response is (successful|a client error|a server error)$`,
		[]string{"the response is successful", "the response is a client error", "the response is a server error"}},
	{"compare", `^the response (body|header) "([^"]*)" (is not|is|equals|contains|starts with|ends with|matches) "([^"]*)"$`,
		expand(`the response {where} "{sel}" {op} "{v}"`, map[string][]string{"{where}": {"body", "header"}, "{op}": {"is not", "is", "equals", "contains", "starts with", "ends with", "matches"}})},
	{"exists", `^the response (body|header) "([^"]*)" (exists|does not exist)$`,
		expand(`the response {where} "{sel}" {op}`, map[string][]string{"{where}": {"body", "header"}, "{op}": {"exists", "does not exist"}})},
	{"body-equals", `^the response body is:$`, []string{"the response body is:"}},
	{"body-contains", `^the response body contains:$`, []string{"the response body contains:"}},
	{"duration", `^the response time is under (\d+) ?ms$`, []string{"the response time is under {#} ms", "the response time is under {#ms}"}},
	{"capture", `^I capture the response (body|header) "([^"]*)" as "([^"]+)"$`,
		expand(`I capture the response {where} "{sel}" as "{name}"`, map[string][]string{"{where}": {"body", "header"}})},
}

Builtin is the fixed step vocabulary, in registration order.

Functions

func Unquote

func Unquote(s string) string

Unquote strips one pair of surrounding double quotes.

Types

type BuiltinStep

type BuiltinStep struct {
	Name   string
	Regex  string
	Shapes []string
}

BuiltinStep is one of apic test's fixed vocabulary entries. The runner binds handlers by Name; the patterns live here so validation can detect `# @step` phrases that would be ambiguous with them. Shapes spell out the texts the regex accepts with every alternation expanded, so the overlap check can unify a phrase against them word by word. A capture is written the way the regex constrains it: "{x}" for a quoted value, {#} for a number, {#ms} for a number followed by ms, {x} for any single token.

type Phrase

type Phrase struct {
	Text   string   // as written
	Params []string // variable names in order of appearance
	Regex  string   // anchored pattern
}

Phrase is a compiled step phrase.

func Parse

func Parse(text string) (*Phrase, error)

Parse compiles a phrase. Each {name} matches a double-quoted string or a bare word, so `a user named {name} exists` matches both `a user named "alice" exists` and `a user named alice exists`. A placeholder written as "{name}" matches quoted text only.

func (*Phrase) ConflictsWith

func (p *Phrase) ConflictsWith(other *Phrase) bool

ConflictsWith reports whether some step text could match both phrases.

func (*Phrase) ConflictsWithBuiltin

func (p *Phrase) ConflictsWithBuiltin() error

ConflictsWithBuiltin reports whether text matching this phrase could also match a built-in step, which godog treats as ambiguous.

func (*Phrase) Values

func (p *Phrase) Values(args []string) map[string]string

Values pairs captured arguments (one per parameter, in order) with parameter names, stripping surrounding double quotes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL