---------- --format / --no-color / --no-truncate ----------
(t *testing.T)
| 752 | // ---------- --format / --no-color / --no-truncate ---------- |
| 753 | |
| 754 | func TestCmdListTasksFormatJSON(t *testing.T) { |
| 755 | root, db := showListEditDB(t) |
| 756 | insertProject(t, db, "demo", "Demo", filepath.Join(root, "repo"), "high") |
| 757 | insertTask(t, db, "a-ip", "Alpha IP", "in-progress", "high", filepath.Join(root, "repo"), "demo") |
| 758 | insertTask(t, db, "b-bl", "Beta BL", "backlog", "medium", filepath.Join(root, "repo"), nil) |
| 759 | |
| 760 | out := captureStdout(t, func() { |
| 761 | if rc := cmdList([]string{"tasks", "--format", "json"}); rc != 0 { |
| 762 | t.Fatalf("rc=%d", rc) |
| 763 | } |
| 764 | }) |
| 765 | var rows []taskListRow |
| 766 | if err := json.Unmarshal([]byte(out), &rows); err != nil { |
| 767 | t.Fatalf("output is not valid JSON: %v\nout=%q", err, out) |
| 768 | } |
| 769 | if len(rows) != 2 { |
| 770 | t.Fatalf("got %d rows, want 2: %+v", len(rows), rows) |
| 771 | } |
| 772 | // Expect priority sort: high before medium. |
| 773 | if rows[0].Slug != "a-ip" || rows[0].Priority != "high" || rows[0].Status != "in-progress" { |
| 774 | t.Errorf("row 0 unexpected: %+v", rows[0]) |
| 775 | } |
| 776 | if rows[1].Slug != "b-bl" || rows[1].Priority != "medium" || rows[1].Status != "backlog" { |
| 777 | t.Errorf("row 1 unexpected: %+v", rows[1]) |
| 778 | } |
| 779 | if rows[0].Project != "demo" { |
| 780 | t.Errorf("row 0 should carry project=demo, got %q", rows[0].Project) |
| 781 | } |
| 782 | // Floating task must not carry a project value. |
| 783 | if rows[1].Project != "" { |
| 784 | t.Errorf("row 1 should be floating, got project=%q", rows[1].Project) |
| 785 | } |
| 786 | // Names are carried in JSON so consumers get legible titles, not slugs. |
| 787 | if rows[0].Name != "Alpha IP" || rows[1].Name != "Beta BL" { |
| 788 | t.Errorf("names = %q,%q, want \"Alpha IP\",\"Beta BL\"", rows[0].Name, rows[1].Name) |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | func TestCmdListTasksFormatJSONDueRaw(t *testing.T) { |
| 793 | root, db := showListEditDB(t) |
nothing calls this directly
no test coverage detected