@@ -294,6 +294,50 @@ func TestFilterWithSetValue(t *testing.T) {
294294 assert .Len (t , filteredRows , 3 )
295295}
296296
297+ func TestFilterFunc (t * testing.T ) {
298+ const (
299+ colTitle = "title"
300+ colDesc = "description"
301+ )
302+
303+ columns := []Column {NewColumn ("title" , "title" , 10 ).WithFiltered (true )}
304+ rows := []Row {
305+ NewRow (RowData {
306+ colTitle : "AAA" ,
307+ colDesc : "" ,
308+ }),
309+ NewRow (RowData {
310+ colTitle : "BBB" ,
311+ colDesc : "" ,
312+ }),
313+ // Empty
314+ NewRow (RowData {}),
315+ }
316+
317+ filterFunc := func (r Row , s string ) bool {
318+ // Completely arbitrary check for testing purposes
319+ title := fmt .Sprintf ("%v" , r .Data ["title" ])
320+ return title == "AAA" && s == "x"
321+ }
322+
323+ // First check that the table won't match with different case
324+ model := New (columns ).WithRows (rows ).Filtered (true )
325+ model = model .WithFilterInputValue ("x" )
326+
327+ filteredRows := model .getFilteredRows (rows )
328+ assert .Len (t , filteredRows , 0 )
329+
330+ // The filter func should then match the one row
331+ model = model .WithFilterFunc (filterFunc )
332+ filteredRows = model .getFilteredRows (rows )
333+ assert .Len (t , filteredRows , 1 )
334+
335+ // Remove filter
336+ model = model .WithFilterInputValue ("" )
337+ filteredRows = model .getFilteredRows (rows )
338+ assert .Len (t , filteredRows , 3 )
339+ }
340+
297341func BenchmarkFilteredScrolling (b * testing.B ) {
298342 // Scrolling through a filtered table with many rows should be quick
299343 // https://github.com/Evertras/bubble-table/issues/135
0 commit comments