| ... | ... | @@ -1532,3 +1532,43 @@ test "custom help" { |
| 1532 | 1532 | try testing.expectError(error.Help, parseSlice(Args, allocator, &[_][]const u8{"--help"}, options)); |
| 1533 | 1533 | try testing.expectEqualStrings(Args.help, aw.written()); |
| 1534 | 1534 | } |
| 1535 | |
| 1536 | test "description" { |
| 1537 | var arena: std.heap.ArenaAllocator = .init(testing.allocator); |
| 1538 | defer arena.deinit(); |
| 1539 | const allocator = arena.allocator(); |
| 1540 | |
| 1541 | var aw: Writer.Allocating = .init(allocator); |
| 1542 | const options = Options{ .prog = "unused-prog", .writer = &aw.writer }; |
| 1543 | |
| 1544 | const Args = struct { |
| 1545 | pub const description = |
| 1546 | \\This is a description |
| 1547 | ; |
| 1548 | }; |
| 1549 | try testing.expectError(error.Help, parseSlice(Args, allocator, &[_][]const u8{"--help"}, options)); |
| 1550 | try testing.expect(mem.indexOf(u8, aw.written(), Args.description) != null); |
| 1551 | } |
| 1552 | |
| 1553 | test "field help" { |
| 1554 | var arena: std.heap.ArenaAllocator = .init(testing.allocator); |
| 1555 | defer arena.deinit(); |
| 1556 | const allocator = arena.allocator(); |
| 1557 | |
| 1558 | var aw: Writer.Allocating = .init(allocator); |
| 1559 | const options = Options{ .prog = "unused-prog", .writer = &aw.writer }; |
| 1560 | |
| 1561 | const Args = struct { |
| 1562 | named: struct { |
| 1563 | output: []const u8, |
| 1564 | pub const output_help = "help for output"; |
| 1565 | }, |
| 1566 | positional: struct { |
| 1567 | args: []const []const u8 = &.{}, |
| 1568 | pub const args_help = "help for args"; |
| 1569 | }, |
| 1570 | }; |
| 1571 | try testing.expectError(error.Help, parseSlice(Args, allocator, &[_][]const u8{"--help"}, options)); |
| 1572 | try testing.expect(mem.indexOf(u8, aw.written(), @FieldType(Args, "named").output_help) != null); |
| 1573 | try testing.expect(mem.indexOf(u8, aw.written(), @FieldType(Args, "positional").args_help) != null); |
| 1574 | } |