Documentation
¶
Overview ¶
Package gherkin implements a parser for the Gherkin language, used for Story/Feature based Behavior Driven Development.
Basic usage example:
feature, _ := gherkin.ParseGherkinFeature(`
@wip
Feature: Hello World
The world is a beautiful place
So let people be nice to each other
@nice @people
Scenario: Nice people
Given a nice person called "Bob"
And a nice person called "Lisa"
When "Bob" says to "Lisa": "Hello!"
Then "Lisa" should reply to "Bob": "Hello!"
`)
fmt.Printf("feature: %#v %#v\n", feature.Title(), feature.Tags())
fmt.Printf("no. scenarios: %#v\n", len(feature.Scenarios()))
for i, scenario := range feature.Scenarios() {
fmt.Printf("scenario %d: %#v %#v\n", i+1, scenario.Title(), scenario.Tags())
for i, step := range scenario.Steps() {
fmt.Printf(" step %d: %#v %#v\n", i+1, step.StepType(), step.Text())
}
}
Output:
feature: "Hello World" []string{"wip"}
no. scenarios: 1
scenario 1: "Nice people" []string{"nice", "people"}
step 1: "Given" "a nice person called \"Bob\""
step 2: "And" "a nice person called \"Lisa\""
step 3: "When" "\"Bob\" says to \"Lisa\": \"Hello!\""
step 4: "Then" "\"Lisa\" should reply to \"Bob\": \"Hello!\""
Index ¶
Examples ¶
Constants ¶
View Source
const VERSION = "v0.1.7"
Variables ¶
This section is empty.
Functions ¶
func ParseGherkinFeature ¶
Example ¶
package main
import (
"fmt"
"github.com/muhqu/go-gherkin"
)
func main() {
feature, _ := gherkin.ParseGherkinFeature(`
@wip
Feature: Hello World
The world is a beautiful place
So let people be nice to each other
@nice @people
Scenario: Nice people
Given a nice person called "Bob"
And a nice person called "Lisa"
When "Bob" says to "Lisa": "Hello!"
Then "Lisa" should reply to "Bob": "Hello!"
`)
fmt.Printf("feature: %#v %#v\n", feature.Title(), feature.Tags())
fmt.Printf("no. scenarios: %#v\n", len(feature.Scenarios()))
for i, scenario := range feature.Scenarios() {
fmt.Printf("scenario %d: %#v %#v\n", i+1, scenario.Title(), scenario.Tags())
for i, step := range scenario.Steps() {
fmt.Printf(" step %d: %#v %#v\n", i+1, step.StepType(), step.Text())
}
}
}
Output: feature: "Hello World" []string{"wip"} no. scenarios: 1 scenario 1: "Nice people" []string{"nice", "people"} step 1: "Given" "a nice person called \"Bob\"" step 2: "And" "a nice person called \"Lisa\"" step 3: "When" "\"Bob\" says to \"Lisa\": \"Hello!\"" step 4: "Then" "\"Lisa\" should reply to \"Bob\": \"Hello!\""
Types ¶
type EventProcessor ¶
type EventProcessor interface {
ProcessEvent(GherkinEvent)
}
type EventProcessorFn ¶
type EventProcessorFn func(GherkinEvent)
func (EventProcessorFn) ProcessEvent ¶
func (fn EventProcessorFn) ProcessEvent(e GherkinEvent)
type GherkinDOM ¶
type GherkinDOM interface {
Feature() FeatureNode
}
type GherkinDOMParser ¶
type GherkinDOMParser interface {
GherkinParser
GherkinDOM
ParseDOM() (GherkinDOM, error)
ParseFeature() (FeatureNode, error)
}
func NewGherkinDOMParser ¶
func NewGherkinDOMParser(content string) GherkinDOMParser
Example ¶
package main
import (
"fmt"
"github.com/muhqu/go-gherkin"
)
func main() {
gp := gherkin.NewGherkinDOMParser(`
@wip
Feature: Hello World
The world is a beautiful place
So let people be nice to each other
@nice @people
Scenario: Nice people
Given a nice person called "Bob"
And a nice person called "Lisa"
When "Bob" says to "Lisa": "Hello!"
Then "Lisa" should reply to "Bob": "Hello!"
`)
feature := gp.Feature()
fmt.Printf("feature: %#v %#v\n", feature.Title(), feature.Tags())
fmt.Printf("no. scenarios: %#v\n", len(feature.Scenarios()))
scenario1 := feature.Scenarios()[0]
fmt.Printf("scenario 1: %#v %#v\n", scenario1.Title(), scenario1.Tags())
}
Output: feature: "Hello World" []string{"wip"} no. scenarios: 1 scenario 1: "Nice people" []string{"nice", "people"}
type GherkinEvent ¶
type GherkinParser ¶
type GherkinParser interface {
WithLogFn(LogFn)
WithEventProcessor(EventProcessor)
Init()
Parse() error
Execute()
}
func NewGherkinParser ¶
func NewGherkinParser(content string) GherkinParser
Example ¶
package main
import (
"fmt"
"github.com/muhqu/go-gherkin"
)
func main() {
gp := gherkin.NewGherkinParser(`
@wip
Feature: Hello World
The world is a beautiful place
So let people be nice to each other
@nice @people
Scenario: Nice people
Given a nice person called "Bob"
And a nice person called "Lisa"
When "Bob" says to "Lisa": "Hello!"
Then "Lisa" should reply to "Bob": "Hello!"
`)
gp.WithEventProcessor(gherkin.EventProcessorFn(func(e gherkin.GherkinEvent) {
fmt.Println(e)
}))
gp.Init()
err := gp.Parse()
if err != nil {
panic(err)
}
gp.Execute()
}
Output: FeatureEvent("Hello World","The world is a beautiful place\nSo let people be nice to each other",["wip"]) ScenarioEvent("Nice people","",["nice" "people"]) StepEvent("Given","a nice person called \"Bob\"") StepEndEvent() StepEvent("And","a nice person called \"Lisa\"") StepEndEvent() StepEvent("When","\"Bob\" says to \"Lisa\": \"Hello!\"") StepEndEvent() StepEvent("Then","\"Lisa\" should reply to \"Bob\": \"Hello!\"") StepEndEvent() ScenarioEndEvent() FeatureEndEvent()
type LogFn ¶
type LogFn func(msg string, args ...interface{})
Example ¶
package main
import (
"fmt"
"github.com/muhqu/go-gherkin"
)
func main() {
gp := gherkin.NewGherkinParser(`
@wip
Feature: Hello World
The world is a beautiful place
So let people be nice to each other
@nice @people
Scenario: Nice people
Given a nice person called "Bob"
And a nice person called "Lisa"
When "Bob" says to "Lisa": "Hello!"
Then "Lisa" should reply to "Bob": "Hello!"
`)
gp.WithLogFn(func(msg string, args ...interface{}) {
fmt.Printf(msg+"\n", args...)
})
gp.Init()
err := gp.Parse()
if err != nil {
panic(err)
}
gp.Execute()
}
Output: BeginFeature: "Hello World": "The world is a beautiful place\nSo let people be nice to each other" tags:[wip] BeginScenario: "Nice people": "" tags:[nice people] BeginStep: "Given": "a nice person called \"Bob\"" EndStep BeginStep: "And": "a nice person called \"Lisa\"" EndStep BeginStep: "When": "\"Bob\" says to \"Lisa\": \"Hello!\"" EndStep BeginStep: "Then": "\"Lisa\" should reply to \"Bob\": \"Hello!\"" EndStep EndScenario EndFeature
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Sub-Package gherkin/events provides the data-structure types for the evented gherkin parser.
|
Sub-Package gherkin/events provides the data-structure types for the evented gherkin parser. |
|
Sub-Package gherkin/formater provides everything to pretty-print a Gherkin DOM.
|
Sub-Package gherkin/formater provides everything to pretty-print a Gherkin DOM. |
|
Sub-Package gherkin/nodes provides the data-structure types for the gherkin DOM parser.
|
Sub-Package gherkin/nodes provides the data-structure types for the gherkin DOM parser. |
Click to show internal directories.
Click to hide internal directories.
