Skip to content

Commit

Permalink
ghokin: fix missing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
antham committed Nov 18, 2023
1 parent f8cf2a4 commit 5bdad8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ghokin/token_generator.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package ghokin

import (
"github.com/cucumber/gherkin/go/v26"
"errors"

gherkin "github.com/cucumber/gherkin/go/v26"
)

type tokenGenerator struct {
section *section
}

func (t *tokenGenerator) Build(tok *gherkin.Token) (bool, error) {
if tok == nil {
return false, errors.New("token is not defined")

Check warning on line 15 in ghokin/token_generator.go

View check run for this annotation

Codecov / codecov/patch

ghokin/token_generator.go#L15

Added line #L15 was not covered by tests
}
if tok.IsEOF() {
return true, nil
}
Expand Down
14 changes: 10 additions & 4 deletions ghokin/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ func getTagOrCommentPadding(paddings map[gherkin.TokenType]int, indent int, sec
var kind gherkin.TokenType
excluded := []gherkin.TokenType{gherkin.TokenTypeTagLine, gherkin.TokenTypeComment}
if sec.next(excluded) != nil {
kind = sec.next(excluded).kind
if s := sec.next(excluded); s != nil {
kind = s.kind
}
}
if kind == 0 && sec.previous(excluded) != nil {
kind = sec.previous(excluded).kind
if s := sec.previous(excluded); s != nil {
kind = s.kind
}
}
// indent the last comment line at the same level than scenario and background
if sec.next([]gherkin.TokenType{gherkin.TokenTypeEmpty}) == nil {
Expand All @@ -132,8 +136,10 @@ func computeCommand(cmd *exec.Cmd, lines []string, sec *section) (bool, []string

func isDescriptionFeature(sec *section) bool {
excluded := []gherkin.TokenType{gherkin.TokenTypeEmpty}
if sec.previous(excluded) != nil && sec.previous(excluded).kind == gherkin.TokenTypeFeatureLine {
return true
if sec.previous(excluded) != nil {
if s := sec.previous(excluded); s != nil && s.kind == gherkin.TokenTypeFeatureLine {
return true
}
}
return false
}
Expand Down

0 comments on commit 5bdad8a

Please sign in to comment.