Skip to content

Commit

Permalink
Test row filter by pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho committed Jan 21, 2019
1 parent 6d186d4 commit c475ff6
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions appui/row_filter_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package appui

import (
"reflect"
gizak "github.com/gizak/termui"
"github.com/moncho/dry/ui/termui"
"testing"
)

Expand All @@ -10,18 +11,55 @@ func TestRowFilter_ByPattern(t *testing.T) {
pattern string
}
tests := []struct {
name string
rf RowFilter
args args
want RowFilter
name string
filterable FilterableRow
args args
want bool
}{
// TODO: Add test cases.
{
"blabla -> true",
filterable{
columns: []*termui.ParColumn{
&termui.ParColumn{
Par: gizak.Par{Text: "blabla"},
},
},
},
args{
"blabla",
},
true,
},
{
"nope -> false",
filterable{
columns: []*termui.ParColumn{
&termui.ParColumn{
Par: gizak.Par{Text: "yes"},
},
},
},
args{
"nope",
},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.rf.ByPattern(tt.args.pattern); !reflect.DeepEqual(got, tt.want) {
filter := RowFilters.ByPattern(tt.args.pattern)
got := filter(tt.filterable)
if got != tt.want {
t.Errorf("RowFilter.ByPattern() = %v, want %v", got, tt.want)
}
})
}
}

type filterable struct {
columns []*termui.ParColumn
}

func (f filterable) ColumnsForFilter() []*termui.ParColumn {
return f.columns
}

0 comments on commit c475ff6

Please sign in to comment.