diff options
Diffstat (limited to 'clap')
| -rw-r--r-- | clap/args.zig | 15 | ||||
| -rw-r--r-- | clap/codepoint_counting_writer.zig | 7 | ||||
| -rw-r--r-- | clap/parsers.zig | 55 | ||||
| -rw-r--r-- | clap/streaming.zig | 95 |
4 files changed, 76 insertions, 96 deletions
diff --git a/clap/args.zig b/clap/args.zig index d0aaee3..6a424e3 100644 --- a/clap/args.zig +++ b/clap/args.zig | |||
| @@ -1,12 +1,3 @@ | |||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | |||
| 4 | const debug = std.debug; | ||
| 5 | const heap = std.heap; | ||
| 6 | const mem = std.mem; | ||
| 7 | const process = std.process; | ||
| 8 | const testing = std.testing; | ||
| 9 | |||
| 10 | /// An example of what methods should be implemented on an arg iterator. | 1 | /// An example of what methods should be implemented on an arg iterator. |
| 11 | pub const ExampleArgIterator = struct { | 2 | pub const ExampleArgIterator = struct { |
| 12 | pub fn next(iter: *ExampleArgIterator) ?[]const u8 { | 3 | pub fn next(iter: *ExampleArgIterator) ?[]const u8 { |
| @@ -35,7 +26,9 @@ test "SliceIterator" { | |||
| 35 | var iter = SliceIterator{ .args = &args }; | 26 | var iter = SliceIterator{ .args = &args }; |
| 36 | 27 | ||
| 37 | for (args) |a| | 28 | for (args) |a| |
| 38 | try testing.expectEqualStrings(a, iter.next().?); | 29 | try std.testing.expectEqualStrings(a, iter.next().?); |
| 39 | 30 | ||
| 40 | try testing.expectEqual(@as(?[]const u8, null), iter.next()); | 31 | try std.testing.expectEqual(@as(?[]const u8, null), iter.next()); |
| 41 | } | 32 | } |
| 33 | |||
| 34 | const std = @import("std"); | ||
diff --git a/clap/codepoint_counting_writer.zig b/clap/codepoint_counting_writer.zig index e6b9d1c..c445c90 100644 --- a/clap/codepoint_counting_writer.zig +++ b/clap/codepoint_counting_writer.zig | |||
| @@ -1,7 +1,3 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const native_endian = builtin.cpu.arch.endian(); | ||
| 4 | |||
| 5 | /// A Writer that counts how many codepoints has been written to it. | 1 | /// A Writer that counts how many codepoints has been written to it. |
| 6 | /// Expects valid UTF-8 input, and does not validate the input. | 2 | /// Expects valid UTF-8 input, and does not validate the input. |
| 7 | pub fn CodepointCountingWriter(comptime WriterType: type) type { | 3 | pub fn CodepointCountingWriter(comptime WriterType: type) type { |
| @@ -34,6 +30,7 @@ pub fn CodepointCountingWriter(comptime WriterType: type) type { | |||
| 34 | // the number of codepoints up to that point. | 30 | // the number of codepoints up to that point. |
| 35 | // Does not validate UTF-8 beyond checking the start byte. | 31 | // Does not validate UTF-8 beyond checking the start byte. |
| 36 | fn utf8CountCodepointsAllowTruncate(s: []const u8) !struct { bytes: usize, codepoints: usize } { | 32 | fn utf8CountCodepointsAllowTruncate(s: []const u8) !struct { bytes: usize, codepoints: usize } { |
| 33 | const native_endian = @import("builtin").cpu.arch.endian(); | ||
| 37 | var len: usize = 0; | 34 | var len: usize = 0; |
| 38 | 35 | ||
| 39 | const N = @sizeOf(usize); | 36 | const N = @sizeOf(usize); |
| @@ -100,3 +97,5 @@ test "handles partial UTF-8 writes" { | |||
| 100 | 97 | ||
| 101 | try testing.expectEqualSlices(u8, utf8_text, fbs.getWritten()); | 98 | try testing.expectEqualSlices(u8, utf8_text, fbs.getWritten()); |
| 102 | } | 99 | } |
| 100 | |||
| 101 | const std = @import("std"); | ||
diff --git a/clap/parsers.zig b/clap/parsers.zig index 8abdf57..2bf8976 100644 --- a/clap/parsers.zig +++ b/clap/parsers.zig | |||
| @@ -1,8 +1,3 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | const fmt = std.fmt; | ||
| 4 | const testing = std.testing; | ||
| 5 | |||
| 6 | pub const default = .{ | 1 | pub const default = .{ |
| 7 | .string = string, | 2 | .string = string, |
| 8 | .str = string, | 3 | .str = string, |
| @@ -26,46 +21,46 @@ pub fn string(in: []const u8) error{}![]const u8 { | |||
| 26 | } | 21 | } |
| 27 | 22 | ||
| 28 | test "string" { | 23 | test "string" { |
| 29 | try testing.expectEqualStrings("aa", try string("aa")); | 24 | try std.testing.expectEqualStrings("aa", try string("aa")); |
| 30 | } | 25 | } |
| 31 | 26 | ||
| 32 | /// A parser that uses `std.fmt.parseInt` to parse the string into an integer value. | 27 | /// A parser that uses `std.fmt.parseInt` to parse the string into an integer value. |
| 33 | /// See `std.fmt.parseInt` documentation for more information. | 28 | /// See `std.fmt.parseInt` documentation for more information. |
| 34 | pub fn int(comptime T: type, comptime base: u8) fn ([]const u8) fmt.ParseIntError!T { | 29 | pub fn int(comptime T: type, comptime base: u8) fn ([]const u8) std.fmt.ParseIntError!T { |
| 35 | return struct { | 30 | return struct { |
| 36 | fn parse(in: []const u8) fmt.ParseIntError!T { | 31 | fn parse(in: []const u8) std.fmt.ParseIntError!T { |
| 37 | return fmt.parseInt(T, in, base); | 32 | return std.fmt.parseInt(T, in, base); |
| 38 | } | 33 | } |
| 39 | }.parse; | 34 | }.parse; |
| 40 | } | 35 | } |
| 41 | 36 | ||
| 42 | test "int" { | 37 | test "int" { |
| 43 | try testing.expectEqual(@as(u8, 0), try int(u8, 10)("0")); | 38 | try std.testing.expectEqual(@as(u8, 0), try int(u8, 10)("0")); |
| 44 | try testing.expectEqual(@as(u8, 1), try int(u8, 10)("1")); | 39 | try std.testing.expectEqual(@as(u8, 1), try int(u8, 10)("1")); |
| 45 | try testing.expectEqual(@as(u8, 10), try int(u8, 10)("10")); | 40 | try std.testing.expectEqual(@as(u8, 10), try int(u8, 10)("10")); |
| 46 | try testing.expectEqual(@as(u8, 0b10), try int(u8, 2)("10")); | 41 | try std.testing.expectEqual(@as(u8, 0b10), try int(u8, 2)("10")); |
| 47 | try testing.expectEqual(@as(u8, 0x10), try int(u8, 0)("0x10")); | 42 | try std.testing.expectEqual(@as(u8, 0x10), try int(u8, 0)("0x10")); |
| 48 | try testing.expectEqual(@as(u8, 0b10), try int(u8, 0)("0b10")); | 43 | try std.testing.expectEqual(@as(u8, 0b10), try int(u8, 0)("0b10")); |
| 49 | try testing.expectEqual(@as(u16, 0), try int(u16, 10)("0")); | 44 | try std.testing.expectEqual(@as(u16, 0), try int(u16, 10)("0")); |
| 50 | try testing.expectEqual(@as(u16, 1), try int(u16, 10)("1")); | 45 | try std.testing.expectEqual(@as(u16, 1), try int(u16, 10)("1")); |
| 51 | try testing.expectEqual(@as(u16, 10), try int(u16, 10)("10")); | 46 | try std.testing.expectEqual(@as(u16, 10), try int(u16, 10)("10")); |
| 52 | try testing.expectEqual(@as(u16, 0b10), try int(u16, 2)("10")); | 47 | try std.testing.expectEqual(@as(u16, 0b10), try int(u16, 2)("10")); |
| 53 | try testing.expectEqual(@as(u16, 0x10), try int(u16, 0)("0x10")); | 48 | try std.testing.expectEqual(@as(u16, 0x10), try int(u16, 0)("0x10")); |
| 54 | try testing.expectEqual(@as(u16, 0b10), try int(u16, 0)("0b10")); | 49 | try std.testing.expectEqual(@as(u16, 0b10), try int(u16, 0)("0b10")); |
| 55 | } | 50 | } |
| 56 | 51 | ||
| 57 | /// A parser that uses `std.fmt.parseFloat` to parse the string into an float value. | 52 | /// A parser that uses `std.fmt.parseFloat` to parse the string into an float value. |
| 58 | /// See `std.fmt.parseFloat` documentation for more information. | 53 | /// See `std.fmt.parseFloat` documentation for more information. |
| 59 | pub fn float(comptime T: type) fn ([]const u8) fmt.ParseFloatError!T { | 54 | pub fn float(comptime T: type) fn ([]const u8) std.fmt.ParseFloatError!T { |
| 60 | return struct { | 55 | return struct { |
| 61 | fn parse(in: []const u8) fmt.ParseFloatError!T { | 56 | fn parse(in: []const u8) std.fmt.ParseFloatError!T { |
| 62 | return fmt.parseFloat(T, in); | 57 | return std.fmt.parseFloat(T, in); |
| 63 | } | 58 | } |
| 64 | }.parse; | 59 | }.parse; |
| 65 | } | 60 | } |
| 66 | 61 | ||
| 67 | test "float" { | 62 | test "float" { |
| 68 | try testing.expectEqual(@as(f32, 0), try float(f32)("0")); | 63 | try std.testing.expectEqual(@as(f32, 0), try float(f32)("0")); |
| 69 | } | 64 | } |
| 70 | 65 | ||
| 71 | pub const EnumError = error{ | 66 | pub const EnumError = error{ |
| @@ -85,10 +80,10 @@ pub fn enumeration(comptime T: type) fn ([]const u8) EnumError!T { | |||
| 85 | 80 | ||
| 86 | test "enumeration" { | 81 | test "enumeration" { |
| 87 | const E = enum { a, b, c }; | 82 | const E = enum { a, b, c }; |
| 88 | try testing.expectEqual(E.a, try enumeration(E)("a")); | 83 | try std.testing.expectEqual(E.a, try enumeration(E)("a")); |
| 89 | try testing.expectEqual(E.b, try enumeration(E)("b")); | 84 | try std.testing.expectEqual(E.b, try enumeration(E)("b")); |
| 90 | try testing.expectEqual(E.c, try enumeration(E)("c")); | 85 | try std.testing.expectEqual(E.c, try enumeration(E)("c")); |
| 91 | try testing.expectError(EnumError.NameNotPartOfEnum, enumeration(E)("d")); | 86 | try std.testing.expectError(EnumError.NameNotPartOfEnum, enumeration(E)("d")); |
| 92 | } | 87 | } |
| 93 | 88 | ||
| 94 | fn ReturnType(comptime P: type) type { | 89 | fn ReturnType(comptime P: type) type { |
| @@ -98,3 +93,5 @@ fn ReturnType(comptime P: type) type { | |||
| 98 | pub fn Result(comptime P: type) type { | 93 | pub fn Result(comptime P: type) type { |
| 99 | return @typeInfo(ReturnType(P)).error_union.payload; | 94 | return @typeInfo(ReturnType(P)).error_union.payload; |
| 100 | } | 95 | } |
| 96 | |||
| 97 | const std = @import("std"); | ||
diff --git a/clap/streaming.zig b/clap/streaming.zig index eba84bb..4a687a2 100644 --- a/clap/streaming.zig +++ b/clap/streaming.zig | |||
| @@ -1,15 +1,3 @@ | |||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const clap = @import("../clap.zig"); | ||
| 3 | const std = @import("std"); | ||
| 4 | |||
| 5 | const args = clap.args; | ||
| 6 | const debug = std.debug; | ||
| 7 | const heap = std.heap; | ||
| 8 | const io = std.io; | ||
| 9 | const mem = std.mem; | ||
| 10 | const os = std.os; | ||
| 11 | const testing = std.testing; | ||
| 12 | |||
| 13 | /// The result returned from Clap.next | 1 | /// The result returned from Clap.next |
| 14 | pub fn Arg(comptime Id: type) type { | 2 | pub fn Arg(comptime Id: type) type { |
| 15 | return struct { | 3 | return struct { |
| @@ -71,14 +59,14 @@ pub fn Clap(comptime Id: type, comptime ArgIterator: type) type { | |||
| 71 | const arg = arg_info.arg; | 59 | const arg = arg_info.arg; |
| 72 | switch (arg_info.kind) { | 60 | switch (arg_info.kind) { |
| 73 | .long => { | 61 | .long => { |
| 74 | const eql_index = mem.indexOfAny(u8, arg, parser.assignment_separators); | 62 | const eql_index = std.mem.indexOfAny(u8, arg, parser.assignment_separators); |
| 75 | const name = if (eql_index) |i| arg[0..i] else arg; | 63 | const name = if (eql_index) |i| arg[0..i] else arg; |
| 76 | const maybe_value = if (eql_index) |i| arg[i + 1 ..] else null; | 64 | const maybe_value = if (eql_index) |i| arg[i + 1 ..] else null; |
| 77 | 65 | ||
| 78 | for (parser.params) |*param| { | 66 | for (parser.params) |*param| { |
| 79 | const match = param.names.long orelse continue; | 67 | const match = param.names.long orelse continue; |
| 80 | 68 | ||
| 81 | if (!mem.eql(u8, name, match)) | 69 | if (!std.mem.eql(u8, name, match)) |
| 82 | continue; | 70 | continue; |
| 83 | if (param.takes_value == .none) { | 71 | if (param.takes_value == .none) { |
| 84 | if (maybe_value != null) | 72 | if (maybe_value != null) |
| @@ -108,7 +96,7 @@ pub fn Clap(comptime Id: type, comptime ArgIterator: type) type { | |||
| 108 | // If we find a positional with the value `--` then we | 96 | // If we find a positional with the value `--` then we |
| 109 | // interpret the rest of the arguments as positional | 97 | // interpret the rest of the arguments as positional |
| 110 | // arguments. | 98 | // arguments. |
| 111 | if (mem.eql(u8, arg, "--")) { | 99 | if (std.mem.eql(u8, arg, "--")) { |
| 112 | parser.state = .rest_are_positional; | 100 | parser.state = .rest_are_positional; |
| 113 | const value = parser.iter.next() orelse return null; | 101 | const value = parser.iter.next() orelse return null; |
| 114 | return Arg(Id){ .param = param, .value = value }; | 102 | return Arg(Id){ .param = param, .value = value }; |
| @@ -200,11 +188,11 @@ pub fn Clap(comptime Id: type, comptime ArgIterator: type) type { | |||
| 200 | 188 | ||
| 201 | fn parseNextArg(parser: *@This()) !?ArgInfo { | 189 | fn parseNextArg(parser: *@This()) !?ArgInfo { |
| 202 | const full_arg = parser.iter.next() orelse return null; | 190 | const full_arg = parser.iter.next() orelse return null; |
| 203 | if (mem.eql(u8, full_arg, "--") or mem.eql(u8, full_arg, "-")) | 191 | if (std.mem.eql(u8, full_arg, "--") or std.mem.eql(u8, full_arg, "-")) |
| 204 | return ArgInfo{ .arg = full_arg, .kind = .positional }; | 192 | return ArgInfo{ .arg = full_arg, .kind = .positional }; |
| 205 | if (mem.startsWith(u8, full_arg, "--")) | 193 | if (std.mem.startsWith(u8, full_arg, "--")) |
| 206 | return ArgInfo{ .arg = full_arg[2..], .kind = .long }; | 194 | return ArgInfo{ .arg = full_arg[2..], .kind = .long }; |
| 207 | if (mem.startsWith(u8, full_arg, "-")) | 195 | if (std.mem.startsWith(u8, full_arg, "-")) |
| 208 | return ArgInfo{ .arg = full_arg[1..], .kind = .short }; | 196 | return ArgInfo{ .arg = full_arg[1..], .kind = .short }; |
| 209 | 197 | ||
| 210 | return ArgInfo{ .arg = full_arg, .kind = .positional }; | 198 | return ArgInfo{ .arg = full_arg, .kind = .positional }; |
| @@ -219,18 +207,18 @@ pub fn Clap(comptime Id: type, comptime ArgIterator: type) type { | |||
| 219 | } | 207 | } |
| 220 | 208 | ||
| 221 | fn expectArgs( | 209 | fn expectArgs( |
| 222 | parser: *Clap(u8, args.SliceIterator), | 210 | parser: *Clap(u8, clap.args.SliceIterator), |
| 223 | results: []const Arg(u8), | 211 | results: []const Arg(u8), |
| 224 | ) !void { | 212 | ) !void { |
| 225 | for (results) |res| { | 213 | for (results) |res| { |
| 226 | const arg = (try parser.next()) orelse return error.TestFailed; | 214 | const arg = (try parser.next()) orelse return error.TestFailed; |
| 227 | try testing.expectEqual(res.param, arg.param); | 215 | try std.testing.expectEqual(res.param, arg.param); |
| 228 | const expected_value = res.value orelse { | 216 | const expected_value = res.value orelse { |
| 229 | try testing.expectEqual(@as(@TypeOf(arg.value), null), arg.value); | 217 | try std.testing.expectEqual(@as(@TypeOf(arg.value), null), arg.value); |
| 230 | continue; | 218 | continue; |
| 231 | }; | 219 | }; |
| 232 | const actual_value = arg.value orelse return error.TestFailed; | 220 | const actual_value = arg.value orelse return error.TestFailed; |
| 233 | try testing.expectEqualSlices(u8, expected_value, actual_value); | 221 | try std.testing.expectEqualSlices(u8, expected_value, actual_value); |
| 234 | } | 222 | } |
| 235 | 223 | ||
| 236 | if (try parser.next()) |_| | 224 | if (try parser.next()) |_| |
| @@ -238,7 +226,7 @@ fn expectArgs( | |||
| 238 | } | 226 | } |
| 239 | 227 | ||
| 240 | fn expectError( | 228 | fn expectError( |
| 241 | parser: *Clap(u8, args.SliceIterator), | 229 | parser: *Clap(u8, clap.args.SliceIterator), |
| 242 | expected: []const u8, | 230 | expected: []const u8, |
| 243 | ) !void { | 231 | ) !void { |
| 244 | var diag: clap.Diagnostic = .{}; | 232 | var diag: clap.Diagnostic = .{}; |
| @@ -246,13 +234,13 @@ fn expectError( | |||
| 246 | 234 | ||
| 247 | while (parser.next() catch |err| { | 235 | while (parser.next() catch |err| { |
| 248 | var buf: [1024]u8 = undefined; | 236 | var buf: [1024]u8 = undefined; |
| 249 | var fbs = io.fixedBufferStream(&buf); | 237 | var fbs = std.io.fixedBufferStream(&buf); |
| 250 | diag.report(fbs.writer(), err) catch return error.TestFailed; | 238 | diag.report(fbs.writer(), err) catch return error.TestFailed; |
| 251 | try testing.expectEqualStrings(expected, fbs.getWritten()); | 239 | try std.testing.expectEqualStrings(expected, fbs.getWritten()); |
| 252 | return; | 240 | return; |
| 253 | }) |_| {} | 241 | }) |_| {} |
| 254 | 242 | ||
| 255 | try testing.expect(false); | 243 | try std.testing.expect(false); |
| 256 | } | 244 | } |
| 257 | 245 | ||
| 258 | test "short params" { | 246 | test "short params" { |
| @@ -276,12 +264,12 @@ test "short params" { | |||
| 276 | const c = ¶ms[2]; | 264 | const c = ¶ms[2]; |
| 277 | const d = ¶ms[3]; | 265 | const d = ¶ms[3]; |
| 278 | 266 | ||
| 279 | var iter = args.SliceIterator{ .args = &.{ | 267 | var iter = clap.args.SliceIterator{ .args = &.{ |
| 280 | "-a", "-b", "-ab", "-ba", | 268 | "-a", "-b", "-ab", "-ba", |
| 281 | "-c", "0", "-c=0", "-ac", | 269 | "-c", "0", "-c=0", "-ac", |
| 282 | "0", "-ac=0", "-d=0", | 270 | "0", "-ac=0", "-d=0", |
| 283 | } }; | 271 | } }; |
| 284 | var parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 272 | var parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 285 | 273 | ||
| 286 | try expectArgs(&parser, &.{ | 274 | try expectArgs(&parser, &.{ |
| 287 | .{ .param = a }, | 275 | .{ .param = a }, |
| @@ -321,12 +309,12 @@ test "long params" { | |||
| 321 | const cc = ¶ms[2]; | 309 | const cc = ¶ms[2]; |
| 322 | const dd = ¶ms[3]; | 310 | const dd = ¶ms[3]; |
| 323 | 311 | ||
| 324 | var iter = args.SliceIterator{ .args = &.{ | 312 | var iter = clap.args.SliceIterator{ .args = &.{ |
| 325 | "--aa", "--bb", | 313 | "--aa", "--bb", |
| 326 | "--cc", "0", | 314 | "--cc", "0", |
| 327 | "--cc=0", "--dd=0", | 315 | "--cc=0", "--dd=0", |
| 328 | } }; | 316 | } }; |
| 329 | var parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 317 | var parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 330 | 318 | ||
| 331 | try expectArgs(&parser, &.{ | 319 | try expectArgs(&parser, &.{ |
| 332 | .{ .param = aa }, | 320 | .{ .param = aa }, |
| @@ -343,11 +331,11 @@ test "positional params" { | |||
| 343 | .takes_value = .one, | 331 | .takes_value = .one, |
| 344 | }}; | 332 | }}; |
| 345 | 333 | ||
| 346 | var iter = args.SliceIterator{ .args = &.{ | 334 | var iter = clap.args.SliceIterator{ .args = &.{ |
| 347 | "aa", | 335 | "aa", |
| 348 | "bb", | 336 | "bb", |
| 349 | } }; | 337 | } }; |
| 350 | var parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 338 | var parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 351 | 339 | ||
| 352 | try expectArgs(&parser, &.{ | 340 | try expectArgs(&parser, &.{ |
| 353 | .{ .param = ¶ms[0], .value = "aa" }, | 341 | .{ .param = ¶ms[0], .value = "aa" }, |
| @@ -378,14 +366,14 @@ test "all params" { | |||
| 378 | const cc = ¶ms[2]; | 366 | const cc = ¶ms[2]; |
| 379 | const positional = ¶ms[3]; | 367 | const positional = ¶ms[3]; |
| 380 | 368 | ||
| 381 | var iter = args.SliceIterator{ .args = &.{ | 369 | var iter = clap.args.SliceIterator{ .args = &.{ |
| 382 | "-a", "-b", "-ab", "-ba", | 370 | "-a", "-b", "-ab", "-ba", |
| 383 | "-c", "0", "-c=0", "-ac", | 371 | "-c", "0", "-c=0", "-ac", |
| 384 | "0", "-ac=0", "--aa", "--bb", | 372 | "0", "-ac=0", "--aa", "--bb", |
| 385 | "--cc", "0", "--cc=0", "something", | 373 | "--cc", "0", "--cc=0", "something", |
| 386 | "-", "--", "--cc=0", "-a", | 374 | "-", "--", "--cc=0", "-a", |
| 387 | } }; | 375 | } }; |
| 388 | var parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 376 | var parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 389 | 377 | ||
| 390 | try expectArgs(&parser, &.{ | 378 | try expectArgs(&parser, &.{ |
| 391 | .{ .param = aa }, | 379 | .{ .param = aa }, |
| @@ -422,11 +410,11 @@ test "different assignment separators" { | |||
| 422 | 410 | ||
| 423 | const aa = ¶ms[0]; | 411 | const aa = ¶ms[0]; |
| 424 | 412 | ||
| 425 | var iter = args.SliceIterator{ .args = &.{ | 413 | var iter = clap.args.SliceIterator{ .args = &.{ |
| 426 | "-a=0", "--aa=0", | 414 | "-a=0", "--aa=0", |
| 427 | "-a:0", "--aa:0", | 415 | "-a:0", "--aa:0", |
| 428 | } }; | 416 | } }; |
| 429 | var parser = Clap(u8, args.SliceIterator){ | 417 | var parser = Clap(u8, clap.args.SliceIterator){ |
| 430 | .params = ¶ms, | 418 | .params = ¶ms, |
| 431 | .iter = &iter, | 419 | .iter = &iter, |
| 432 | .assignment_separators = "=:", | 420 | .assignment_separators = "=:", |
| @@ -453,35 +441,38 @@ test "errors" { | |||
| 453 | }, | 441 | }, |
| 454 | }; | 442 | }; |
| 455 | 443 | ||
| 456 | var iter = args.SliceIterator{ .args = &.{"q"} }; | 444 | var iter = clap.args.SliceIterator{ .args = &.{"q"} }; |
| 457 | var parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 445 | var parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 458 | try expectError(&parser, "Invalid argument 'q'\n"); | 446 | try expectError(&parser, "Invalid argument 'q'\n"); |
| 459 | 447 | ||
| 460 | iter = args.SliceIterator{ .args = &.{"-q"} }; | 448 | iter = clap.args.SliceIterator{ .args = &.{"-q"} }; |
| 461 | parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 449 | parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 462 | try expectError(&parser, "Invalid argument '-q'\n"); | 450 | try expectError(&parser, "Invalid argument '-q'\n"); |
| 463 | 451 | ||
| 464 | iter = args.SliceIterator{ .args = &.{"--q"} }; | 452 | iter = clap.args.SliceIterator{ .args = &.{"--q"} }; |
| 465 | parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 453 | parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 466 | try expectError(&parser, "Invalid argument '--q'\n"); | 454 | try expectError(&parser, "Invalid argument '--q'\n"); |
| 467 | 455 | ||
| 468 | iter = args.SliceIterator{ .args = &.{"--q=1"} }; | 456 | iter = clap.args.SliceIterator{ .args = &.{"--q=1"} }; |
| 469 | parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 457 | parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 470 | try expectError(&parser, "Invalid argument '--q'\n"); | 458 | try expectError(&parser, "Invalid argument '--q'\n"); |
| 471 | 459 | ||
| 472 | iter = args.SliceIterator{ .args = &.{"-a=1"} }; | 460 | iter = clap.args.SliceIterator{ .args = &.{"-a=1"} }; |
| 473 | parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 461 | parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 474 | try expectError(&parser, "The argument '-a' does not take a value\n"); | 462 | try expectError(&parser, "The argument '-a' does not take a value\n"); |
| 475 | 463 | ||
| 476 | iter = args.SliceIterator{ .args = &.{"--aa=1"} }; | 464 | iter = clap.args.SliceIterator{ .args = &.{"--aa=1"} }; |
| 477 | parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 465 | parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 478 | try expectError(&parser, "The argument '--aa' does not take a value\n"); | 466 | try expectError(&parser, "The argument '--aa' does not take a value\n"); |
| 479 | 467 | ||
| 480 | iter = args.SliceIterator{ .args = &.{"-c"} }; | 468 | iter = clap.args.SliceIterator{ .args = &.{"-c"} }; |
| 481 | parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 469 | parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 482 | try expectError(&parser, "The argument '-c' requires a value but none was supplied\n"); | 470 | try expectError(&parser, "The argument '-c' requires a value but none was supplied\n"); |
| 483 | 471 | ||
| 484 | iter = args.SliceIterator{ .args = &.{"--cc"} }; | 472 | iter = clap.args.SliceIterator{ .args = &.{"--cc"} }; |
| 485 | parser = Clap(u8, args.SliceIterator){ .params = ¶ms, .iter = &iter }; | 473 | parser = Clap(u8, clap.args.SliceIterator){ .params = ¶ms, .iter = &iter }; |
| 486 | try expectError(&parser, "The argument '--cc' requires a value but none was supplied\n"); | 474 | try expectError(&parser, "The argument '--cc' requires a value but none was supplied\n"); |
| 487 | } | 475 | } |
| 476 | |||
| 477 | const clap = @import("../clap.zig"); | ||
| 478 | const std = @import("std"); | ||