fix utf8 character counting for printers

Этот коммит содержится в:
gedi 2016-06-02 08:36:27 +03:00
родитель 9bde6a2b9b
коммит 726a451b7a
2 изменённых файлов: 12 добавлений и 9 удалений

Просмотреть файл

@ -6,6 +6,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"time" "time"
"unicode/utf8"
"github.com/DATA-DOG/godog/gherkin" "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 { func (f *pretty) length(node interface{}) int {
switch t := node.(type) { switch t := node.(type) {
case *gherkin.Background: 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: 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: 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: 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)) panic(fmt.Sprintf("unexpected node %T to determine length", node))
} }

Просмотреть файл

@ -6,9 +6,9 @@ import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"regexp" "regexp"
"runtime"
"strconv" "strconv"
"strings" "strings"
"unicode/utf8"
"github.com/DATA-DOG/godog/gherkin" "github.com/DATA-DOG/godog/gherkin"
) )
@ -372,13 +372,15 @@ func (s *Suite) runScenario(scenario *gherkin.Scenario, b *gherkin.Background) (
func (s *Suite) printStepDefinitions() { func (s *Suite) printStepDefinitions() {
var longest int var longest int
for _, def := range s.steps { for _, def := range s.steps {
if longest < len(def.Expr.String()) { n := utf8.RuneCountInString(def.Expr.String())
longest = len(def.Expr.String()) if longest < n {
longest = n
} }
} }
for _, def := range s.steps { for _, def := range s.steps {
location := runtime.FuncForPC(def.hv.Pointer()).Name() n := utf8.RuneCountInString(def.Expr.String())
spaces := strings.Repeat(" ", longest-len(def.Expr.String())) location := def.funcName()
spaces := strings.Repeat(" ", longest-n)
fmt.Println(cl(def.Expr.String(), yellow)+spaces, cl("# "+location, black)) fmt.Println(cl(def.Expr.String(), yellow)+spaces, cl("# "+location, black))
} }
if len(s.steps) == 0 { if len(s.steps) == 0 {