Skip to content

Commit

Permalink
testing: add tests for issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlazar committed Apr 15, 2022
1 parent f912170 commit d018702
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ require (
github.com/mattn/go-runewidth v0.0.13
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
50 changes: 33 additions & 17 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestTable_WriteTable(t *testing.T) {
r := require.New(t)

var buf bytes.Buffer

// write the table
tab := Table{
func TestingTable() Table {
return Table{
Headers: []string{"something", "another"},
Rows: [][]string{
{"1", "2"},
Expand All @@ -23,6 +18,15 @@ func TestTable_WriteTable(t *testing.T) {
{"but this one is longer", "shorter now"},
},
}
}

func TestTable_WriteTable(t *testing.T) {
r := require.New(t)

var buf bytes.Buffer

// write the table
tab := TestingTable()
err := tab.WriteTable(&buf, nil)
r.NoError(err)

Expand All @@ -47,11 +51,7 @@ func TestTable_WriteLargeTable(t *testing.T) {
var buf bytes.Buffer

// write the table
tab := Table{
Headers: []string{"something"},
Rows: [][]string{},
}

tab := TestingTable()
for i := 0; i < 200; i++ {
tab.Rows = append(tab.Rows, []string{"x"})
}
Expand All @@ -67,11 +67,27 @@ func TestTable_WriteEmptyTable(t *testing.T) {
var buf bytes.Buffer

// write the table
tab := Table{
Headers: []string{"something"},
Rows: [][]string{},
}
tab := TestingTable()
err := tab.WriteTable(&buf, nil)
r.NoError(err)
r.Equal(2, len(strings.Split(buf.String(), "\n")))
r.Equal(6, len(strings.Split(buf.String(), "\n")))
}

func TestTable_WriteColorNoAlts(t *testing.T) {
r := require.New(t)

var buf bytes.Buffer

// write the table
tab := TestingTable()
c := Config{
ShowIndex: true,
Color: true,
AlternateColors: true,
AltColorCodes: nil,
TitleColorCode: "",
}
err := tab.WriteTable(&buf, &c)
r.NoError(err)
r.Equal(6, len(strings.Split(buf.String(), "\n")))
}

0 comments on commit d018702

Please sign in to comment.