From a580983c8980f86003e6017097575bd0b2307130 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Sun, 27 Aug 2023 16:29:20 -0700 Subject: [PATCH] add failing test, reproducing issue in src/main --- src/url.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/url.zig b/src/url.zig index 26b1977..639e76e 100644 --- a/src/url.zig +++ b/src/url.zig @@ -195,3 +195,33 @@ test "can urlencode a complex object" { .{}, ); } + +const Filter = struct { + name: ?[]const u8 = null, + values: ?[][]const u8 = null, + + pub fn fieldNameFor(_: @This(), comptime field_name: []const u8) []const u8 { + const mappings = .{ + .name = "Name", + .values = "Value", + }; + return @field(mappings, field_name); + } +}; + +const Request: type = struct { + filters: ?[]Filter = null, + region_names: ?[][]const u8 = null, + dry_run: ?bool = null, + all_regions: ?bool = null, +}; +test "can urlencode an EC2 Filter" { + try testencode( + std.testing.allocator, + "name=foo&values=bar", + Request{ + .filters = @constCast(&[_]Filter{.{ .name = "foo", .values = @constCast(&[_][]const u8{"bar"}) }}), + }, + .{}, + ); +}