fix utf8 character counting for printers
Этот коммит содержится в:
родитель
9bde6a2b9b
коммит
726a451b7a
2 изменённых файлов: 12 добавлений и 9 удалений
|
@ -6,6 +6,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/DATA-DOG/godog/gherkin"
|
||||
)
|
||||
|
@ -377,13 +378,13 @@ func (f *pretty) line(loc *gherkin.Location) string {
|
|||
func (f *pretty) length(node interface{}) int {
|
||||
switch t := node.(type) {
|
||||
case *gherkin.Background:
|
||||
return f.indent + len(strings.TrimSpace(t.Keyword)+": "+t.Name)
|
||||
return f.indent + utf8.RuneCountInString(strings.TrimSpace(t.Keyword)+": "+t.Name)
|
||||
case *gherkin.Step:
|
||||
return f.indent*2 + len(strings.TrimSpace(t.Keyword)+" "+t.Text)
|
||||
return f.indent*2 + utf8.RuneCountInString(strings.TrimSpace(t.Keyword)+" "+t.Text)
|
||||
case *gherkin.Scenario:
|
||||
return f.indent + len(strings.TrimSpace(t.Keyword)+": "+t.Name)
|
||||
return f.indent + utf8.RuneCountInString(strings.TrimSpace(t.Keyword)+": "+t.Name)
|
||||
case *gherkin.ScenarioOutline:
|
||||
return f.indent + len(strings.TrimSpace(t.Keyword)+": "+t.Name)
|
||||
return f.indent + utf8.RuneCountInString(strings.TrimSpace(t.Keyword)+": "+t.Name)
|
||||
}
|
||||
panic(fmt.Sprintf("unexpected node %T to determine length", node))
|
||||
}
|
||||
|
|
12
suite.go
12
suite.go
|
@ -6,9 +6,9 @@ import (
|
|||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/DATA-DOG/godog/gherkin"
|
||||
)
|
||||
|
@ -372,13 +372,15 @@ func (s *Suite) runScenario(scenario *gherkin.Scenario, b *gherkin.Background) (
|
|||
func (s *Suite) printStepDefinitions() {
|
||||
var longest int
|
||||
for _, def := range s.steps {
|
||||
if longest < len(def.Expr.String()) {
|
||||
longest = len(def.Expr.String())
|
||||
n := utf8.RuneCountInString(def.Expr.String())
|
||||
if longest < n {
|
||||
longest = n
|
||||
}
|
||||
}
|
||||
for _, def := range s.steps {
|
||||
location := runtime.FuncForPC(def.hv.Pointer()).Name()
|
||||
spaces := strings.Repeat(" ", longest-len(def.Expr.String()))
|
||||
n := utf8.RuneCountInString(def.Expr.String())
|
||||
location := def.funcName()
|
||||
spaces := strings.Repeat(" ", longest-n)
|
||||
fmt.Println(cl(def.Expr.String(), yellow)+spaces, cl("# "+location, black))
|
||||
}
|
||||
if len(s.steps) == 0 {
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче