mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
refactor: tidy; make Options bodies call setters
This commit is contained in:
+53
-29
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user