Skip to content

Commit

Permalink
refactor(table): use … instead of ... + remove TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Sep 14, 2024
1 parent a4de8aa commit b617ee8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,9 @@ func (t *Table) constructRow(index int, isOverflow bool) string {
for c := 0; c < t.data.Columns(); c++ {
cellWidth := t.widths[c]

// TODO(fix): small cells should be using '…' instead of '...'. This is rendered wrong when
// then cellWidth is greater than 3 but the visible cell (ie. after styling) is smaller than 3.
cell := "..."
switch {
case !isOverflow:
cell := "…"
if !isOverflow {
cell = t.data.At(index, c)
case cellWidth < 3:
cell = "…"
}

cells = append(cells, t.style(index+1, c).
Expand Down
8 changes: 4 additions & 4 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ func TestTableHeightShrink(t *testing.T) {
β”‚ Chinese β”‚ Nǐn hǎo β”‚ Nǐ hǎo β”‚
β”‚ French β”‚ Bonjour β”‚ Salut β”‚
β”‚ Japanese β”‚ こんにけは β”‚ やあ β”‚
β”‚ ... β”‚ ... β”‚ ... β”‚
β”‚ … β”‚ … β”‚ … β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
`)

Expand All @@ -1074,12 +1074,11 @@ func TestTableHeightMinimum(t *testing.T) {
Row("4", "Russian", "Zdravstvuyte", "Privet").
Row("5", "Spanish", "Hola", "ΒΏQuΓ© tal?")

// TODO: the ID column should be using '…' instead of '...'. How to check cell width while accounting for padding?
expected := strings.TrimSpace(`
β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ID β”‚ LANGUAGE β”‚ FORMAL β”‚ INFORMAL β”‚
β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ .. β”‚ ... β”‚ ... β”‚ ... β”‚
β”‚ … β”‚ … β”‚ … β”‚ … β”‚
β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
`)

Expand Down Expand Up @@ -1110,7 +1109,8 @@ func TestTableHeightMinimumShowData(t *testing.T) {
}

func TestTableHeightWithOffset(t *testing.T) {
//This test exists to check for a bug / edge case when the table has an offset and the height is exact.
// This test exists to check for a bug/edge case when the table has an
// offset and the height is set.

table := New().
Height(8).
Expand Down

0 comments on commit b617ee8

Please sign in to comment.