gherkin

package module
v0.0.0-...-3e3e490 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2019 License: MIT Imports: 15 Imported by: 0

README

Gherkin

This is a copy of https://github.com/cucumber/cucumber but just the go files.

Documentation

Index

Constants

View Source
const (
	DEFAULT_DIALECT                 = "en"
	COMMENT_PREFIX                  = "#"
	TAG_PREFIX                      = "@"
	TITLE_KEYWORD_SEPARATOR         = ":"
	TABLE_CELL_SEPARATOR            = '|'
	ESCAPE_CHAR                     = '\\'
	ESCAPED_NEWLINE                 = 'n'
	DOCSTRING_SEPARATOR             = "\"\"\""
	DOCSTRING_ALTERNATIVE_SEPARATOR = "```"
)

Variables

This section is empty.

Functions

func Messages

func Messages(
	paths []string,
	sourceStream io.Reader,
	language string,
	includeSource bool,
	includeGherkinDocument bool,
	includePickles bool,
	outStream io.Writer,
	json bool,
) ([]messages.Envelope, error)

func ParseGherkinDocument

func ParseGherkinDocument(in io.Reader) (gherkinDocument *messages.GherkinDocument, err error)

func ParseGherkinDocumentForLanguage

func ParseGherkinDocumentForLanguage(in io.Reader, language string) (gherkinDocument *messages.GherkinDocument, err error)

func Pickles

func Pickles(gherkinDocument messages.GherkinDocument, uri string, source string) []*messages.Pickle

Types

type AstBuilder

type AstBuilder interface {
	Builder
	GetGherkinDocument() *messages.GherkinDocument
}

func NewAstBuilder

func NewAstBuilder() AstBuilder

type Builder

type Builder interface {
	Build(*Token) (bool, error)
	StartRule(RuleType) (bool, error)
	EndRule(RuleType) (bool, error)
	Reset()
}

type GherkinDialect

type GherkinDialect struct {
	Language string
	Name     string
	Native   string
	Keywords map[string][]string
}

func (*GherkinDialect) BackgroundKeywords

func (g *GherkinDialect) BackgroundKeywords() []string

func (*GherkinDialect) ExamplesKeywords

func (g *GherkinDialect) ExamplesKeywords() []string

func (*GherkinDialect) FeatureKeywords

func (g *GherkinDialect) FeatureKeywords() []string

func (*GherkinDialect) RuleKeywords

func (g *GherkinDialect) RuleKeywords() []string

func (*GherkinDialect) ScenarioKeywords

func (g *GherkinDialect) ScenarioKeywords() []string

func (*GherkinDialect) ScenarioOutlineKeywords

func (g *GherkinDialect) ScenarioOutlineKeywords() []string

func (*GherkinDialect) StepKeywords

func (g *GherkinDialect) StepKeywords() []string

type GherkinDialectProvider

type GherkinDialectProvider interface {
	GetDialect(language string) *GherkinDialect
}

func GherkinDialectsBuildin

func GherkinDialectsBuildin() GherkinDialectProvider

Builtin dialects for af (Afrikaans), am (Armenian), an (Aragonese), ar (Arabic), ast (Asturian), az (Azerbaijani), bg (Bulgarian), bm (Malay), bs (Bosnian), ca (Catalan), cs (Czech), cy-GB (Welsh), da (Danish), de (German), el (Greek), em (Emoji), en (English), en-Scouse (Scouse), en-au (Australian), en-lol (LOLCAT), en-old (Old English), en-pirate (Pirate), eo (Esperanto), es (Spanish), et (Estonian), fa (Persian), fi (Finnish), fr (French), ga (Irish), gj (Gujarati), gl (Galician), he (Hebrew), hi (Hindi), hr (Croatian), ht (Creole), hu (Hungarian), id (Indonesian), is (Icelandic), it (Italian), ja (Japanese), jv (Javanese), ka (Georgian), kn (Kannada), ko (Korean), lt (Lithuanian), lu (Luxemburgish), lv (Latvian), mk-Cyrl (Macedonian), mk-Latn (Macedonian (Latin)), mn (Mongolian), nl (Dutch), no (Norwegian), pa (Panjabi), pl (Polish), pt (Portuguese), ro (Romanian), ru (Russian), sk (Slovak), sl (Slovenian), sr-Cyrl (Serbian), sr-Latn (Serbian (Latin)), sv (Swedish), ta (Tamil), th (Thai), tl (Telugu), tlh (Klingon), tr (Turkish), tt (Tatar), uk (Ukrainian), ur (Urdu), uz (Uzbek), vi (Vietnamese), zh-CN (Chinese simplified), zh-TW (Chinese traditional)

type Line

type Line struct {
	LineText        string
	LineNumber      int
	TrimmedLineText string
	AtEof           bool
}

func (*Line) Indent

func (g *Line) Indent() int

func (*Line) IsEmpty

func (g *Line) IsEmpty() bool

func (*Line) IsEof

func (g *Line) IsEof() bool

func (*Line) StartsWith

func (g *Line) StartsWith(prefix string) bool

type LineSpan

type LineSpan struct {
	Column int
	Text   string
}

func (*LineSpan) String

func (l *LineSpan) String() string

type Location

type Location struct {
	Line   int
	Column int
}

type Matcher

type Matcher interface {
	MatchEOF(line *Line) (bool, *Token, error)
	MatchEmpty(line *Line) (bool, *Token, error)
	MatchComment(line *Line) (bool, *Token, error)
	MatchTagLine(line *Line) (bool, *Token, error)
	MatchFeatureLine(line *Line) (bool, *Token, error)
	MatchRuleLine(line *Line) (bool, *Token, error)
	MatchBackgroundLine(line *Line) (bool, *Token, error)
	MatchScenarioLine(line *Line) (bool, *Token, error)
	MatchExamplesLine(line *Line) (bool, *Token, error)
	MatchStepLine(line *Line) (bool, *Token, error)
	MatchDocStringSeparator(line *Line) (bool, *Token, error)
	MatchTableRow(line *Line) (bool, *Token, error)
	MatchLanguage(line *Line) (bool, *Token, error)
	MatchOther(line *Line) (bool, *Token, error)
	Reset()
}

func NewLanguageMatcher

func NewLanguageMatcher(gdp GherkinDialectProvider, language string) Matcher

func NewMatcher

func NewMatcher(gdp GherkinDialectProvider) Matcher

type Parser

type Parser interface {
	StopAtFirstError(b bool)
	Parse(s Scanner, m Matcher) (err error)
}

func NewParser

func NewParser(b Builder) Parser

type RuleType

type RuleType int
const (
	RuleTypeNone RuleType = iota

	RuleTypeEOF
	RuleTypeEmpty
	RuleTypeComment
	RuleTypeTagLine
	RuleTypeFeatureLine
	RuleTypeRuleLine
	RuleTypeBackgroundLine
	RuleTypeScenarioLine
	RuleTypeExamplesLine
	RuleTypeStepLine
	RuleTypeDocStringSeparator
	RuleTypeTableRow
	RuleTypeLanguage
	RuleTypeOther
	RuleTypeGherkinDocument
	RuleTypeFeature
	RuleTypeFeatureHeader
	RuleTypeRule
	RuleTypeRuleHeader
	RuleTypeBackground
	RuleTypeScenarioDefinition
	RuleTypeScenario
	RuleTypeExamplesDefinition
	RuleTypeExamples
	RuleTypeExamplesTable
	RuleTypeStep
	RuleTypeStepArg
	RuleTypeDataTable
	RuleTypeDocString
	RuleTypeTags
	RuleTypeDescriptionHelper
	RuleTypeDescription
)

func (RuleType) IsEOF

func (t RuleType) IsEOF() bool

func (RuleType) Name

func (t RuleType) Name() string

type Scanner

type Scanner interface {
	Scan() (line *Line, atEof bool, err error)
}

The Scanner reads a gherkin doc (typically read from a .feature file) and creates a token for each line. The tokens are passed to the parser, which outputs an AST (Abstract Syntax Tree).

If the scanner sees a # language header, it will reconfigure itself dynamically to look for Gherkin keywords for the associated language. The keywords are defined in gherkin-languages.json.

func NewScanner

func NewScanner(r io.Reader) Scanner

type Token

type Token struct {
	Type           TokenType
	Keyword        string
	Text           string
	Items          []*LineSpan
	GherkinDialect string
	Indent         string
	Location       *Location
}

func (*Token) IsEOF

func (t *Token) IsEOF() bool

func (*Token) String

func (t *Token) String() string

type TokenType

type TokenType int
const (
	TokenTypeNone TokenType = iota
	TokenTypeEOF
	TokenTypeEmpty
	TokenTypeComment
	TokenTypeTagLine
	TokenTypeFeatureLine
	TokenTypeRuleLine
	TokenTypeBackgroundLine
	TokenTypeScenarioLine
	TokenTypeExamplesLine
	TokenTypeStepLine
	TokenTypeDocStringSeparator
	TokenTypeTableRow
	TokenTypeLanguage
	TokenTypeOther
)

func (TokenType) Name

func (t TokenType) Name() string

func (TokenType) RuleType

func (t TokenType) RuleType() RuleType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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