diff options
Diffstat (limited to 'clap/streaming.zig')
| -rw-r--r-- | clap/streaming.zig | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/clap/streaming.zig b/clap/streaming.zig index a2a0ca8..e2f1311 100644 --- a/clap/streaming.zig +++ b/clap/streaming.zig | |||
| @@ -203,7 +203,7 @@ pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type { | |||
| 203 | }; | 203 | }; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, results: []const Arg(u8)) void { | 206 | fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, results: []const Arg(u8)) !void { |
| 207 | var iter = args.SliceIterator{ .args = args_strings }; | 207 | var iter = args.SliceIterator{ .args = args_strings }; |
| 208 | var c = StreamingClap(u8, args.SliceIterator){ | 208 | var c = StreamingClap(u8, args.SliceIterator){ |
| 209 | .params = params, | 209 | .params = params, |
| @@ -211,22 +211,22 @@ fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, r | |||
| 211 | }; | 211 | }; |
| 212 | 212 | ||
| 213 | for (results) |res| { | 213 | for (results) |res| { |
| 214 | const arg = (c.next() catch unreachable) orelse unreachable; | 214 | const arg = (try c.next()) orelse return error.TestFailed; |
| 215 | testing.expectEqual(res.param, arg.param); | 215 | try testing.expectEqual(res.param, arg.param); |
| 216 | const expected_value = res.value orelse { | 216 | const expected_value = res.value orelse { |
| 217 | testing.expectEqual(@as(@TypeOf(arg.value), null), arg.value); | 217 | try testing.expectEqual(@as(@TypeOf(arg.value), null), arg.value); |
| 218 | continue; | 218 | continue; |
| 219 | }; | 219 | }; |
| 220 | const actual_value = arg.value orelse unreachable; | 220 | const actual_value = arg.value orelse return error.TestFailed; |
| 221 | testing.expectEqualSlices(u8, expected_value, actual_value); | 221 | try testing.expectEqualSlices(u8, expected_value, actual_value); |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | if (c.next() catch unreachable) |_| | 224 | if (try c.next()) |_| |
| 225 | unreachable; | 225 | return error.TestFailed; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, expected: []const u8) void { | 228 | fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, expected: []const u8) !void { |
| 229 | var diag = clap.Diagnostic{}; | 229 | var diag: clap.Diagnostic = undefined; |
| 230 | var iter = args.SliceIterator{ .args = args_strings }; | 230 | var iter = args.SliceIterator{ .args = args_strings }; |
| 231 | var c = StreamingClap(u8, args.SliceIterator){ | 231 | var c = StreamingClap(u8, args.SliceIterator){ |
| 232 | .params = params, | 232 | .params = params, |
| @@ -236,12 +236,12 @@ fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, exp | |||
| 236 | while (c.next() catch |err| { | 236 | while (c.next() catch |err| { |
| 237 | var buf: [1024]u8 = undefined; | 237 | var buf: [1024]u8 = undefined; |
| 238 | var fbs = io.fixedBufferStream(&buf); | 238 | var fbs = io.fixedBufferStream(&buf); |
| 239 | diag.report(fbs.writer(), err) catch unreachable; | 239 | diag.report(fbs.writer(), err) catch return error.TestFailed; |
| 240 | testing.expectEqualStrings(expected, fbs.getWritten()); | 240 | try testing.expectEqualStrings(expected, fbs.getWritten()); |
| 241 | return; | 241 | return; |
| 242 | }) |_| {} | 242 | }) |_| {} |
| 243 | 243 | ||
| 244 | testing.expect(false); | 244 | try testing.expect(false); |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | test "short params" { | 247 | test "short params" { |
| @@ -265,14 +265,14 @@ test "short params" { | |||
| 265 | const c = ¶ms[2]; | 265 | const c = ¶ms[2]; |
| 266 | const d = ¶ms[3]; | 266 | const d = ¶ms[3]; |
| 267 | 267 | ||
| 268 | testNoErr( | 268 | try testNoErr( |
| 269 | ¶ms, | 269 | ¶ms, |
| 270 | &[_][]const u8{ | 270 | &.{ |
| 271 | "-a", "-b", "-ab", "-ba", | 271 | "-a", "-b", "-ab", "-ba", |
| 272 | "-c", "0", "-c=0", "-ac", | 272 | "-c", "0", "-c=0", "-ac", |
| 273 | "0", "-ac=0", "-d=0", | 273 | "0", "-ac=0", "-d=0", |
| 274 | }, | 274 | }, |
| 275 | &[_]Arg(u8){ | 275 | &.{ |
| 276 | .{ .param = a }, | 276 | .{ .param = a }, |
| 277 | .{ .param = b }, | 277 | .{ .param = b }, |
| 278 | .{ .param = a }, | 278 | .{ .param = a }, |
| @@ -311,14 +311,14 @@ test "long params" { | |||
| 311 | const cc = ¶ms[2]; | 311 | const cc = ¶ms[2]; |
| 312 | const dd = ¶ms[3]; | 312 | const dd = ¶ms[3]; |
| 313 | 313 | ||
| 314 | testNoErr( | 314 | try testNoErr( |
| 315 | ¶ms, | 315 | ¶ms, |
| 316 | &[_][]const u8{ | 316 | &.{ |
| 317 | "--aa", "--bb", | 317 | "--aa", "--bb", |
| 318 | "--cc", "0", | 318 | "--cc", "0", |
| 319 | "--cc=0", "--dd=0", | 319 | "--cc=0", "--dd=0", |
| 320 | }, | 320 | }, |
| 321 | &[_]Arg(u8){ | 321 | &.{ |
| 322 | .{ .param = aa }, | 322 | .{ .param = aa }, |
| 323 | .{ .param = bb }, | 323 | .{ .param = bb }, |
| 324 | .{ .param = cc, .value = "0" }, | 324 | .{ .param = cc, .value = "0" }, |
| @@ -334,10 +334,10 @@ test "positional params" { | |||
| 334 | .takes_value = .one, | 334 | .takes_value = .one, |
| 335 | }}; | 335 | }}; |
| 336 | 336 | ||
| 337 | testNoErr( | 337 | try testNoErr( |
| 338 | ¶ms, | 338 | ¶ms, |
| 339 | &[_][]const u8{ "aa", "bb" }, | 339 | &.{ "aa", "bb" }, |
| 340 | &[_]Arg(u8){ | 340 | &.{ |
| 341 | .{ .param = ¶ms[0], .value = "aa" }, | 341 | .{ .param = ¶ms[0], .value = "aa" }, |
| 342 | .{ .param = ¶ms[0], .value = "bb" }, | 342 | .{ .param = ¶ms[0], .value = "bb" }, |
| 343 | }, | 343 | }, |
| @@ -367,16 +367,16 @@ test "all params" { | |||
| 367 | const cc = ¶ms[2]; | 367 | const cc = ¶ms[2]; |
| 368 | const positional = ¶ms[3]; | 368 | const positional = ¶ms[3]; |
| 369 | 369 | ||
| 370 | testNoErr( | 370 | try testNoErr( |
| 371 | ¶ms, | 371 | ¶ms, |
| 372 | &[_][]const u8{ | 372 | &.{ |
| 373 | "-a", "-b", "-ab", "-ba", | 373 | "-a", "-b", "-ab", "-ba", |
| 374 | "-c", "0", "-c=0", "-ac", | 374 | "-c", "0", "-c=0", "-ac", |
| 375 | "0", "-ac=0", "--aa", "--bb", | 375 | "0", "-ac=0", "--aa", "--bb", |
| 376 | "--cc", "0", "--cc=0", "something", | 376 | "--cc", "0", "--cc=0", "something", |
| 377 | "-", "--", "--cc=0", "-a", | 377 | "-", "--", "--cc=0", "-a", |
| 378 | }, | 378 | }, |
| 379 | &[_]Arg(u8){ | 379 | &.{ |
| 380 | .{ .param = aa }, | 380 | .{ .param = aa }, |
| 381 | .{ .param = bb }, | 381 | .{ .param = bb }, |
| 382 | .{ .param = aa }, | 382 | .{ .param = aa }, |
| @@ -413,12 +413,12 @@ test "errors" { | |||
| 413 | .takes_value = .one, | 413 | .takes_value = .one, |
| 414 | }, | 414 | }, |
| 415 | }; | 415 | }; |
| 416 | testErr(¶ms, &[_][]const u8{"q"}, "Invalid argument 'q'\n"); | 416 | try testErr(¶ms, &.{"q"}, "Invalid argument 'q'\n"); |
| 417 | testErr(¶ms, &[_][]const u8{"-q"}, "Invalid argument '-q'\n"); | 417 | try testErr(¶ms, &.{"-q"}, "Invalid argument '-q'\n"); |
| 418 | testErr(¶ms, &[_][]const u8{"--q"}, "Invalid argument '--q'\n"); | 418 | try testErr(¶ms, &.{"--q"}, "Invalid argument '--q'\n"); |
| 419 | testErr(¶ms, &[_][]const u8{"--q=1"}, "Invalid argument '--q'\n"); | 419 | try testErr(¶ms, &.{"--q=1"}, "Invalid argument '--q'\n"); |
| 420 | testErr(¶ms, &[_][]const u8{"-a=1"}, "The argument '-a' does not take a value\n"); | 420 | try testErr(¶ms, &.{"-a=1"}, "The argument '-a' does not take a value\n"); |
| 421 | testErr(¶ms, &[_][]const u8{"--aa=1"}, "The argument '--aa' does not take a value\n"); | 421 | try testErr(¶ms, &.{"--aa=1"}, "The argument '--aa' does not take a value\n"); |
| 422 | testErr(¶ms, &[_][]const u8{"-c"}, "The argument '-c' requires a value but none was supplied\n"); | 422 | try testErr(¶ms, &.{"-c"}, "The argument '-c' requires a value but none was supplied\n"); |
| 423 | testErr(¶ms, &[_][]const u8{"--cc"}, "The argument '--cc' requires a value but none was supplied\n"); | 423 | try testErr(¶ms, &.{"--cc"}, "The argument '--cc' requires a value but none was supplied\n"); |
| 424 | } | 424 | } |