@@ -294,6 +294,51 @@ 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+
321+ return title == "AAA" && s == "x"
322+ }
323+
324+ // First check that the table won't match with different case
325+ model := New (columns ).WithRows (rows ).Filtered (true )
326+ model = model .WithFilterInputValue ("x" )
327+
328+ filteredRows := model .getFilteredRows (rows )
329+ assert .Len (t , filteredRows , 0 )
330+
331+ // The filter func should then match the one row
332+ model = model .WithFilterFunc (filterFunc )
333+ filteredRows = model .getFilteredRows (rows )
334+ assert .Len (t , filteredRows , 1 )
335+
336+ // Remove filter
337+ model = model .WithFilterInputValue ("" )
338+ filteredRows = model .getFilteredRows (rows )
339+ assert .Len (t , filteredRows , 3 )
340+ }
341+
297342func BenchmarkFilteredScrolling (b * testing.B ) {
298343 // Scrolling through a filtered table with many rows should be quick
299344 // https://github.com/Evertras/bubble-table/issues/135
0 commit comments