-
Notifications
You must be signed in to change notification settings - Fork 105
/
rendering.go
45 lines (42 loc) · 1.27 KB
/
rendering.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package test
import "github.com/cucumber/messages-go/v10"
// RenderExecutedGitCommands provides the textual Gherkin table representation of the given executed Git commands.
// The DataTable table matches the structure of the given Gherkin table.
func RenderExecutedGitCommands(commands []ExecutedGitCommand, table *messages.PickleStepArgument_PickleTable) DataTable {
tableHasBranches := table.Rows[0].Cells[0].Value == "BRANCH"
result := DataTable{}
if tableHasBranches {
result.AddRow("BRANCH", "COMMAND")
} else {
result.AddRow("COMMAND")
}
lastBranch := ""
for _, cmd := range commands {
if tableHasBranches {
switch {
case cmd.Branch == lastBranch:
result.AddRow("", cmd.Command)
case cmd.Branch == "":
result.AddRow("<none>", cmd.Command)
default:
result.AddRow(cmd.Branch, cmd.Command)
}
} else {
result.AddRow(cmd.Command)
}
lastBranch = cmd.Branch
}
return result
}
// RenderTable provides the textual Gherkin representation of the given Gherkin table.
func RenderTable(table *messages.PickleStepArgument_PickleTable) string {
result := DataTable{}
for _, row := range table.Rows {
values := []string{}
for _, cell := range row.Cells {
values = append(values, cell.Value)
}
result.AddRow(values...)
}
return result.String()
}