Skip to content

Commit

Permalink
Merge cfb8904 into c982558
Browse files Browse the repository at this point in the history
  • Loading branch information
sriv authored Sep 16, 2020
2 parents c982558 + cfb8904 commit 95332a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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

0 comments on commit 95332a5

Please # to comment.