refactor: tidy; make Options bodies call setters

This commit is contained in:
bashbunni
2024-09-11 15:38:29 -07:00
parent 87b61f8646
commit 1c621af57d
2 changed files with 81 additions and 53 deletions
+53 -29
View File
@@ -10,23 +10,61 @@ import (
)
func TestFromValues(t *testing.T) {
input := "foo1,bar1\nfoo2,bar2\nfoo3,bar3"
table := New().
Headers("Foo", "Bar")
table.FromValues(input, ",")
t.Run("Headers", func(t *testing.T) {
input := "foo1,bar1\nfoo2,bar2\nfoo3,bar3"
table := New().
Headers("Foo", "Bar")
table.FromValues(input, ",")
if len(table.rows) != 3 {
t.Fatalf("expect table to have 3 rows but it has %d", len(table.rows))
}
if len(table.rows) != 3 {
t.Fatalf("expect table to have 3 rows but it has %d", len(table.rows))
}
expect := [][]string{
{"foo1", "bar1"},
{"foo2", "bar2"},
{"foo3", "bar3"},
}
if !reflect.DeepEqual(table.rows, expect) {
t.Fatal("table rows is not equals to the input")
}
expect := [][]string{
{"foo1", "bar1"},
{"foo2", "bar2"},
{"foo3", "bar3"},
}
if !reflect.DeepEqual(table.rows, expect) {
t.Fatal("table rows is not equals to the input")
}
})
t.Run("WithColumns", func(t *testing.T) {
input := "foo1,bar1\nfoo2,bar2\nfoo3,bar3"
table := New(WithColumns([]Column{{Title: "Foo"}, {Title: "Bar"}}))
table.FromValues(input, ",")
if len(table.rows) != 3 {
t.Fatalf("expect table to have 3 rows but it has %d", len(table.rows))
}
expect := [][]string{
{"foo1", "bar1"},
{"foo2", "bar2"},
{"foo3", "bar3"},
}
if !reflect.DeepEqual(table.rows, expect) {
t.Fatal("table rows is not equals to the input")
}
})
t.Run("WithHeaders", func(t *testing.T) {
input := "foo1,bar1\nfoo2,bar2\nfoo3,bar3"
table := New(WithHeaders([]Column{{Title: "Foo"}, {Title: "Bar"}}))
table.FromValues(input, ",")
if len(table.rows) != 3 {
t.Fatalf("expect table to have 3 rows but it has %d", len(table.rows))
}
expect := [][]string{
{"foo1", "bar1"},
{"foo2", "bar2"},
{"foo3", "bar3"},
}
if !reflect.DeepEqual(table.rows, expect) {
t.Fatal("table rows is not equals to the input")
}
})
}
func TestFromValuesWithTabSeparator(t *testing.T) {
@@ -47,20 +85,6 @@ func TestFromValuesWithTabSeparator(t *testing.T) {
}
}
func deepEqual(a, b []Row) bool {
if len(a) != len(b) {
return false
}
for i, r := range a {
for j, f := range r {
if f != b[i][j] {
return false
}
}
}
return true
}
func TestTableAlignment(t *testing.T) {
t.Run("No border", func(t *testing.T) {
s := DefaultStyles()