Documentation ¶
Index ¶
- type Assist
- func (a *Assist) CompareToInstance(actual interface{}, table *godog.Table) error
- func (a *Assist) CompareToSlice(actual interface{}, table *godog.Table) error
- func (a *Assist) CreateInstance(tp interface{}, table *godog.Table) (interface{}, error)
- func (a *Assist) CreateSlice(tp interface{}, table *godog.Table) (interface{}, error)
- func (a *Assist) ParseMap(table *godog.Table) (map[string]string, error)
- func (a *Assist) ParseSlice(table *godog.Table) ([]map[string]string, error)
- func (a *Assist) RegisterComparer(i interface{}, comparer CompareFunc)
- func (a *Assist) RegisterParser(i interface{}, parser ParseFunc)
- func (a *Assist) RemoveComparer(i interface{})
- func (a *Assist) RemoveParser(i interface{})
- type CompareFunc
- type ParseFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assist ¶
type Assist struct {
// contains filtered or unexported fields
}
Assist provides utility methods to deal with Gherkin tables.
func NewDefault ¶
func NewDefault() *Assist
NewDefault creates a new Assist instance with all the default parsers and comparers.
func (*Assist) CompareToInstance ¶
CompareToInstance compares an actual value to the expected fields from a Gherkin table.
Example ¶
table := NewTable([][]string{ {"Name", "John"}, // | Name | John | {"Height", "182"}, // | Height | 182 | }) actual := &Person{ Name: "John", Height: 182, } assist := assistdog.NewDefault() err := assist.CompareToInstance(actual, table) if err != nil { panic(err) }
Output:
func (*Assist) CompareToSlice ¶
CompareToSlice compares an actual slice of values to the expected rows from a Gherkin table.
Example ¶
table := NewTable([][]string{ {"Name", "Height"}, // | Name | Height | {"John", "182"}, // | John | 182 | {"Mary", "170"}, // | Mary | 170 | }) actual := []*Person{ {Name: "John", Height: 182}, {Name: "Mary", Height: 170}, } assist := assistdog.NewDefault() err := assist.CompareToSlice(actual, table) if err != nil { panic(err) }
Output:
func (*Assist) CreateInstance ¶
CreateInstance takes a type and a Gherkin table and returns an instance of that type filled with the table's parsed values. The table must have exactly two columns, where the first represents the field names and the second represents the values.
Example ¶
table := NewTable([][]string{ {"Name", "John"}, // | Name | John | {"Height", "182"}, // | Height | 182 | }) assist := assistdog.NewDefault() result, err := assist.CreateInstance(new(Person), table) if err != nil { panic(err) } reflect.DeepEqual(result, &Person{ Name: "John", Height: 182, })
Output:
func (*Assist) CreateSlice ¶
CreateSlice takes a type and a Gherkin table and returns a slice of that type filled with each row as an instance. The first row acts as a header and provides the field names for each column.
Example ¶
table := NewTable([][]string{ {"Name", "Height"}, // | Name | Height | {"John", "182"}, // | John | 182 | {"Mary", "170"}, // | Mary | 170 | }) assist := assistdog.NewDefault() result, err := assist.CreateSlice(new(Person), table) if err != nil { panic(err) } reflect.DeepEqual(result, []*Person{ {Name: "John", Height: 182}, {Name: "Mary", Height: 170}, })
Output:
func (*Assist) ParseMap ¶
ParseMap takes a Gherkin table and returns a map that represents it. The table must have exactly two columns, where the first represents the key and the second represents the value.
func (*Assist) ParseSlice ¶
ParseSlice takes a Gherkin table and returns a slice of maps representing each row. The first row acts as a header and provides the keys.
func (*Assist) RegisterComparer ¶
func (a *Assist) RegisterComparer(i interface{}, comparer CompareFunc)
RegisterComparer registers a new value comparer for a type. If a previous comparer already exists for the given type, it will be replaced.
func (*Assist) RegisterParser ¶
RegisterParser registers a new value parser for a type. If a previous parser already exists for the given type, it will be replaced.
func (*Assist) RemoveComparer ¶
func (a *Assist) RemoveComparer(i interface{})
RemoveComparer removes the value comparer for a type.
func (*Assist) RemoveParser ¶
func (a *Assist) RemoveParser(i interface{})
RemoveParser removes the value parser for a type.
type CompareFunc ¶
CompareFunc compares a raw string value from a table to an actual typed value. If the values are considered a match, no error should be returned. Otherwise, an error that describes the differences should be returned.