You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Table type can have value accessor methods by column name.
Currently table values can be accessed using tbl.Rows[0].Cells[0] to fetch first element of first row.
This can be enhanced to access value using column name as: tbl.getColumn("columnName").get(0) so that its more explicit and avoids index out of range exceptions.
Better way?
The text was updated successfully, but these errors were encountered:
For anyone looking.
I map a Table to a slice of maps, where each row becomes a slice element with the column header being the index in the map, using this;
// TableParameters can be used when a table of parameters is used with a step.// The function provides a map per row of which the index is the name of the cell from the header.// https://docs.gauge.org/writing-specifications.html?os=linux&language=python&ide=vscode#table-parametersfuncTableParameters(tbl*m.Table) []map[string]string {
rows:=make([]map[string]string, len(tbl.Rows))
fori, r:=rangetbl.Rows {
cells:=make(map[string]string, len(r.Cells))
forcol, cell:=ranger.Cells {
cells[tbl.Headers.Cells[col]] =cell
}
rows[i] =cells
}
returnrows
}
Having for example this specification;
* Almost all words have vowels
|Word |Vowel Count|
|------|-----------|
|Gauge |3 |
|Mingle|2 |
|Snap |1 |
|GoCD |1 |
|Rhythm|0 |
You could do this in your implementation;
var_=gauge.Step("Almost all words have vowels <table>", func(tbl*m.Table) {
for_, row:=rangeTableParameters(tbl) {
word:=row[`Word`]
expectedCount, err:=strconv.Atoi(row[`Vowel Count`])
[...]
Table type can have value accessor methods by column name.
Currently table values can be accessed using
tbl.Rows[0].Cells[0]
to fetch first element of first row.This can be enhanced to access value using column name as:
tbl.getColumn("columnName").get(0)
so that its more explicit and avoids index out of range exceptions.Better way?
The text was updated successfully, but these errors were encountered: