Skip to content

Commit

Permalink
test(table): add additional filter test
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Oct 5, 2023
1 parent 959f516 commit 31c811e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,37 @@ func TestFilter(t *testing.T) {
}
}

func TestFilterInverse(t *testing.T) {
data := NewStringData().
Item("Chinese", "Nǐn hǎo", "Nǐ hǎo").
Item("French", "Bonjour", "Salut").
Item("Japanese", "こんにけは", "やあ").
Item("Russian", "Zdravstvuyte", "Privet").
Item("Spanish", "Hola", "ΒΏQuΓ© tal?")

filter := NewFilter(data).Filter(func(row Row) bool {
return row.Column(0) == "French"
})

table := New().
Border(lipgloss.NormalBorder()).
StyleFunc(TableStyle).
Headers("LANGUAGE", "FORMAL", "INFORMAL").
Data(filter)

expected := strings.TrimSpace(`
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LANGUAGE β”‚ FORMAL β”‚ INFORMAL β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ French β”‚ Bonjour β”‚ Salut β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
`)

if table.String() != expected {
t.Fatalf("expected:\n\n%s\n\ngot:\n\n%s", expected, table.String())
}
}

func debug(s string) string {
return strings.ReplaceAll(s, " ", ".")
}

0 comments on commit 31c811e

Please sign in to comment.