MCPcopy
hub / github.com/moncho/dry / TestTableModel_SortNumericWithANSI

Function TestTableModel_SortNumericWithANSI

appui/table_model_test.go:277–302  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

275}
276
277func TestTableModel_SortNumericWithANSI(t *testing.T) {
278 cols := []Column{{Title: "Name"}, {Title: "Pids"}}
279 table := NewTableModel(cols)
280 table.SetSize(80, 25)
281 // Wrap numbers in ANSI color codes like monitor model does
282 rows := []TableRow{
283 testRow{id: "1", cols: []string{"a", ColorFg("9", DryTheme.FgMuted)}},
284 testRow{id: "2", cols: []string{"b", ColorFg("10", DryTheme.FgMuted)}},
285 testRow{id: "3", cols: []string{"c", ColorFg("2", DryTheme.FgMuted)}},
286 testRow{id: "4", cols: []string{"d", ColorFg("100", DryTheme.FgMuted)}},
287 }
288 table.SetRows(rows)
289
290 // Sort by column 1 (Pids)
291 table.NextSort() // sort field = 1
292 table.Sort()
293
294 // Numeric ascending: 2, 9, 10, 100
295 expectedIDs := []string{"3", "1", "2", "4"}
296 for i, want := range expectedIDs {
297 r := table.filtered[i]
298 if r.ID() != want {
299 t.Errorf("row %d: expected id %q, got %q", i, want, r.ID())
300 }
301 }
302}
303
304func TestTableModel_SortPreservedAfterSetRows(t *testing.T) {
305 cols := []Column{{Title: "Name"}, {Title: "Value"}}

Callers

nothing calls this directly

Calls 7

SetSizeMethod · 0.95
SetRowsMethod · 0.95
NextSortMethod · 0.95
SortMethod · 0.95
NewTableModelFunction · 0.85
ColorFgFunction · 0.85
IDMethod · 0.65

Tested by

no test coverage detected