Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

compute cell length using runes when formatting, fixes #1755 #1759

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,15 @@ func FormatTable(table *gauge.Table) string {
}

func addPaddingToCell(cellValue string, width int) string {
padding := getRepeatedChars(" ", width-len(cellValue))
return fmt.Sprintf("%s%s", cellValue, padding)
cellRunes := []rune(cellValue)
padding := getRepeatedChars(" ", width-len(cellRunes))
return fmt.Sprintf("%s%s", string(cellRunes), padding)
}

func findLongestCellWidth(columnCells []gauge.TableCell, minValue int) int {
longestLength := minValue
for _, cellValue := range columnCells {
cellValueLen := len(cellValue.GetValue())
cellValueLen := len([]rune(cellValue.GetValue()))
if cellValueLen > longestLength {
longestLength = cellValueLen
}
Expand Down
20 changes: 20 additions & 0 deletions formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ func (s *MySuite) TestFormatTable(c *C) {
c.Assert(got, Equals, want)
}

func (s *MySuite) TestFormatTableWithUmlautChars(c *C) {
// umlaut characters are unicode and can take up twice the space of regular chars
cell1 := gauge.TableCell{Value: "Büsingen", CellType: gauge.Static}
cell2 := gauge.TableCell{Value: "Hauptstraße", CellType: gauge.Static}

headers := []string{"col1", "col2"}
cols := [][]gauge.TableCell{{cell1}, {cell2}}

table := gauge.NewTable(headers, cols, 10)

got := FormatTable(table)
want := `
|col1 |col2 |
|--------|-----------|
|Büsingen|Hauptstraße|
`

c.Assert(got, Equals, want)
}

func (s *MySuite) TestFormatConcepts(c *C) {
dictionary := gauge.NewConceptDictionary()
step1 := &gauge.Step{Value: "sdsf", LineText: "sdsf", IsConcept: true, LineNo: 1, PreComments: []*gauge.Comment{&gauge.Comment{Value: "COMMENT", LineNo: 1}}}
Expand Down