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 ¶
const MaxParams = 6
MaxParams is the most parameters a phrase may declare.
Variables ¶
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|cookie) "([^"]*)" (is not|is|equals|contains|starts with|ends with|matches) "([^"]*)"$`, expand(`the response {where} "{sel}" {op} "{v}"`, map[string][]string{"{where}": {"body", "header", "cookie"}, "{op}": {"is not", "is", "equals", "contains", "starts with", "ends with", "matches"}})}, {"exists", `^the response (body|header|cookie) "([^"]*)" (exists|does not exist)$`, expand(`the response {where} "{sel}" {op}`, map[string][]string{"{where}": {"body", "header", "cookie"}, "{op}": {"exists", "does not exist"}})}, {"length", `^the response body "([^"]*)" has length (\d+)$`, []string{`the response body "{sel}" has length {#}`}}, {"type", `^the response body "([^"]*)" is (a string|a number|an integer|a boolean|an array|an object|null)$`, expand(`the response body "{sel}" is {type}`, map[string][]string{"{type}": {"a string", "a number", "an integer", "a boolean", "an array", "an object", "null"}})}, {"empty", `^the response body "([^"]*)" (is empty|is not empty)$`, []string{`the response body "{sel}" is empty`, `the response body "{sel}" is not empty`}}, {"schema", `^the response body(?: "([^"]*)")? matches the schema "([^"]*)"$`, []string{`the response body matches the schema "{file}"`, `the response body "{sel}" matches the schema "{file}"`}}, {"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|cookie) "([^"]*)" as "([^"]+)"$`, expand(`I capture the response {where} "{sel}" as "{name}"`, map[string][]string{"{where}": {"body", "header", "cookie"}})}, }
Builtin is the fixed step vocabulary, in registration order.
Functions ¶
Types ¶
type BuiltinStep ¶
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 ¶
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 ¶
ConflictsWith reports whether some step text could match both phrases.
func (*Phrase) ConflictsWithBuiltin ¶
ConflictsWithBuiltin reports whether text matching this phrase could also match a built-in step, which godog treats as ambiguous.