(t *testing.T)
| 159 | } |
| 160 | |
| 161 | func TestNextID_JSONFormat(t *testing.T) { |
| 162 | resetNextIDFlags() |
| 163 | nextIDFormat = "json" |
| 164 | |
| 165 | tmpDir := createNextIDTestFiles(t, map[string]string{ |
| 166 | "001-task.md": `--- |
| 167 | id: "001" |
| 168 | title: "Task one" |
| 169 | status: pending |
| 170 | priority: medium |
| 171 | created: 2026-02-14 |
| 172 | --- |
| 173 | `, |
| 174 | "002-task.md": `--- |
| 175 | id: "002" |
| 176 | title: "Task two" |
| 177 | status: completed |
| 178 | priority: high |
| 179 | created: 2026-02-14 |
| 180 | --- |
| 181 | `, |
| 182 | }) |
| 183 | |
| 184 | oldStdout := os.Stdout |
| 185 | r, w, _ := os.Pipe() |
| 186 | os.Stdout = w |
| 187 | |
| 188 | err := runNextID(nextIDCmd, []string{tmpDir}) |
| 189 | |
| 190 | w.Close() |
| 191 | os.Stdout = oldStdout |
| 192 | |
| 193 | if err != nil { |
| 194 | t.Fatalf("unexpected error: %v", err) |
| 195 | } |
| 196 | |
| 197 | var buf bytes.Buffer |
| 198 | buf.ReadFrom(r) |
| 199 | |
| 200 | var result nextid.Result |
| 201 | if err := json.Unmarshal(buf.Bytes(), &result); err != nil { |
| 202 | t.Fatalf("failed to parse JSON: %v\noutput: %s", err, buf.String()) |
| 203 | } |
| 204 | |
| 205 | if result.NextID != "003" { |
| 206 | t.Errorf("NextID = %q, want %q", result.NextID, "003") |
| 207 | } |
| 208 | if result.MaxID != "002" { |
| 209 | t.Errorf("MaxID = %q, want %q", result.MaxID, "002") |
| 210 | } |
| 211 | if result.Total != 2 { |
| 212 | t.Errorf("Total = %d, want 2", result.Total) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | func TestNextID_UnsupportedFormat(t *testing.T) { |
| 217 | resetNextIDFlags() |
nothing calls this directly
no test coverage detected