| 275 | } |
| 276 | |
| 277 | func 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 | |
| 304 | func TestTableModel_SortPreservedAfterSetRows(t *testing.T) { |
| 305 | cols := []Column{{Title: "Name"}, {Title: "Value"}} |