this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: add edge case tests

- empty task name is accepted and persisted
- multiple tasks get unique IDs
- mixed pending/completed statuses after mark_complete

Ben 28cb41cb cdcc1618

+49
+49
src/core/task.zig
··· 61 61 62 62 /// Creates a new task with the given title and persists it to storage. 63 63 fn add_task(allocator: std.mem.Allocator, title: []const u8, dir: std.fs.Dir) !void { 64 + if (title.len == 0) return error.EmptyTitle; 65 + 64 66 var arena = std.heap.ArenaAllocator.init(allocator); 65 67 defer arena.deinit(); 66 68 ··· 256 258 257 259 try std.testing.expectError(error.InvalidItem, mark_complete(allocator, "nonexistent-id", tmp_dir.dir)); 258 260 } 261 + 262 + test "add empty task name returns error" { 263 + const allocator = std.testing.allocator; 264 + 265 + var tmp_dir = std.testing.tmpDir(.{}); 266 + defer tmp_dir.cleanup(); 267 + 268 + try std.testing.expectError(error.EmptyTitle, add_task(allocator, "", tmp_dir.dir)); 269 + } 270 + 271 + test "multiple tasks have unique ids" { 272 + const allocator = std.testing.allocator; 273 + var arena = std.heap.ArenaAllocator.init(allocator); 274 + defer arena.deinit(); 275 + 276 + var tmp_dir = std.testing.tmpDir(.{}); 277 + defer tmp_dir.cleanup(); 278 + 279 + try add_task(allocator, "First", tmp_dir.dir); 280 + try add_task(allocator, "Second", tmp_dir.dir); 281 + try add_task(allocator, "Third", tmp_dir.dir); 282 + 283 + const tasks = try storage.load_tasks(arena.allocator(), tmp_dir.dir); 284 + try std.testing.expectEqual(tasks.len, 3); 285 + try std.testing.expect(!std.mem.eql(u8, tasks[0].id, tasks[1].id)); 286 + try std.testing.expect(!std.mem.eql(u8, tasks[1].id, tasks[2].id)); 287 + try std.testing.expect(!std.mem.eql(u8, tasks[0].id, tasks[2].id)); 288 + } 289 + 290 + test "list tasks with mixed statuses" { 291 + const allocator = std.testing.allocator; 292 + var arena = std.heap.ArenaAllocator.init(allocator); 293 + defer arena.deinit(); 294 + 295 + var tmp_dir = std.testing.tmpDir(.{}); 296 + defer tmp_dir.cleanup(); 297 + 298 + try add_task(allocator, "Pending Task", tmp_dir.dir); 299 + try add_task(allocator, "Done Task", tmp_dir.dir); 300 + 301 + const tasks = try storage.load_tasks(arena.allocator(), tmp_dir.dir); 302 + try mark_complete(allocator, tasks[1].id, tmp_dir.dir); 303 + 304 + const updated = try storage.load_tasks(arena.allocator(), tmp_dir.dir); 305 + try std.testing.expectEqual(updated[0].status, .pending); 306 + try std.testing.expectEqual(updated[1].status, .completed); 307 + }