Skip to content

Commit

Permalink
table: handle negative WidthMax values (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Jan 4, 2024
1 parent a0c7cb6 commit f26db87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion table/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type ColumnConfig struct {
}

func (c ColumnConfig) getWidthMaxEnforcer() WidthEnforcer {
if c.WidthMax == 0 {
if c.WidthMax <= 0 {
return widthEnforcerNone
}
if c.WidthMaxEnforcer != nil {
Expand Down
14 changes: 14 additions & 0 deletions table/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ func TestColumnConfig_getWidthMaxEnforcer(t *testing.T) {
assert.Equal(t, "1234567890", widthEnforcer("1234567890", 1000))
})

t.Run("negative width enforcer", func(t *testing.T) {
cc := ColumnConfig{
WidthMax: -10,
}

widthEnforcer := cc.getWidthMaxEnforcer()
assert.Equal(t, "1234567890", widthEnforcer("1234567890", 0))
assert.Equal(t, "1234567890", widthEnforcer("1234567890", 1))
assert.Equal(t, "1234567890", widthEnforcer("1234567890", 5))
assert.Equal(t, "1234567890", widthEnforcer("1234567890", 10))
assert.Equal(t, "1234567890", widthEnforcer("1234567890", 100))
assert.Equal(t, "1234567890", widthEnforcer("1234567890", 1000))
})

t.Run("custom width enforcer (1)", func(t *testing.T) {
cc := ColumnConfig{
WidthMax: 10,
Expand Down

0 comments on commit f26db87

Please sign in to comment.