summaryrefslogtreecommitdiff
path: root/clap/args.zig
diff options
context:
space:
mode:
Diffstat (limited to 'clap/args.zig')
-rw-r--r--clap/args.zig86
1 files changed, 43 insertions, 43 deletions
diff --git a/clap/args.zig b/clap/args.zig
index f9ad218..555e8ab 100644
--- a/clap/args.zig
+++ b/clap/args.zig
@@ -34,8 +34,8 @@ pub const SliceIterator = struct {
34}; 34};
35 35
36test "SliceIterator" { 36test "SliceIterator" {
37 const args = &[_][]const u8{ "A", "BB", "CCC" }; 37 const args = [_][]const u8{ "A", "BB", "CCC" };
38 var iter = SliceIterator{ .args = args }; 38 var iter = SliceIterator{ .args = &args };
39 39
40 for (args) |a| { 40 for (args) |a| {
41 const b = try iter.next(); 41 const b = try iter.next();
@@ -266,76 +266,76 @@ pub const ShellIterator = struct {
266 } 266 }
267}; 267};
268 268
269fn testShellIteratorOk(str: []const u8, allocations: usize, expect: []const []const u8) void { 269fn testShellIteratorOk(str: []const u8, allocations: usize, expect: []const []const u8) !void {
270 var allocator = testing.FailingAllocator.init(testing.allocator, allocations); 270 var allocator = testing.FailingAllocator.init(testing.allocator, allocations);
271 var it = ShellIterator.init(&allocator.allocator, str); 271 var it = ShellIterator.init(&allocator.allocator, str);
272 defer it.deinit(); 272 defer it.deinit();
273 273
274 for (expect) |e| { 274 for (expect) |e| {
275 if (it.next()) |actual| { 275 if (it.next()) |actual| {
276 testing.expect(actual != null); 276 try testing.expect(actual != null);
277 testing.expectEqualStrings(e, actual.?); 277 try testing.expectEqualStrings(e, actual.?);
278 } else |err| testing.expectEqual(@as(anyerror![]const u8, e), err); 278 } else |err| try testing.expectEqual(@as(anyerror![]const u8, e), err);
279 } 279 }
280 280
281 if (it.next()) |actual| { 281 if (it.next()) |actual| {
282 testing.expectEqual(@as(?[]const u8, null), actual); 282 try testing.expectEqual(@as(?[]const u8, null), actual);
283 testing.expectEqual(allocations, allocator.allocations); 283 try testing.expectEqual(allocations, allocator.allocations);
284 } else |err| testing.expectEqual(@as(anyerror!void, {}), err); 284 } else |err| try testing.expectEqual(@as(anyerror!void, {}), err);
285} 285}
286 286
287fn testShellIteratorErr(str: []const u8, expect: anyerror) void { 287fn testShellIteratorErr(str: []const u8, expect: anyerror) !void {
288 var it = ShellIterator.init(testing.allocator, str); 288 var it = ShellIterator.init(testing.allocator, str);
289 defer it.deinit(); 289 defer it.deinit();
290 290
291 while (it.next() catch |err| { 291 while (it.next() catch |err| {
292 testing.expectError(expect, @as(anyerror!void, err)); 292 try testing.expectError(expect, @as(anyerror!void, err));
293 return; 293 return;
294 }) |_| {} 294 }) |_| {}
295 295
296 testing.expectError(expect, @as(anyerror!void, {})); 296 try testing.expectError(expect, @as(anyerror!void, {}));
297} 297}
298 298
299test "ShellIterator" { 299test "ShellIterator" {
300 testShellIteratorOk("a", 0, &[_][]const u8{"a"}); 300 try testShellIteratorOk("a", 0, &.{"a"});
301 testShellIteratorOk("'a'", 0, &[_][]const u8{"a"}); 301 try testShellIteratorOk("'a'", 0, &.{"a"});
302 testShellIteratorOk("\"a\"", 0, &[_][]const u8{"a"}); 302 try testShellIteratorOk("\"a\"", 0, &.{"a"});
303 testShellIteratorOk("a b", 0, &[_][]const u8{ "a", "b" }); 303 try testShellIteratorOk("a b", 0, &.{ "a", "b" });
304 testShellIteratorOk("'a' b", 0, &[_][]const u8{ "a", "b" }); 304 try testShellIteratorOk("'a' b", 0, &.{ "a", "b" });
305 testShellIteratorOk("\"a\" b", 0, &[_][]const u8{ "a", "b" }); 305 try testShellIteratorOk("\"a\" b", 0, &.{ "a", "b" });
306 testShellIteratorOk("a 'b'", 0, &[_][]const u8{ "a", "b" }); 306 try testShellIteratorOk("a 'b'", 0, &.{ "a", "b" });
307 testShellIteratorOk("a \"b\"", 0, &[_][]const u8{ "a", "b" }); 307 try testShellIteratorOk("a \"b\"", 0, &.{ "a", "b" });
308 testShellIteratorOk("'a b'", 0, &[_][]const u8{"a b"}); 308 try testShellIteratorOk("'a b'", 0, &.{"a b"});
309 testShellIteratorOk("\"a b\"", 0, &[_][]const u8{"a b"}); 309 try testShellIteratorOk("\"a b\"", 0, &.{"a b"});
310 testShellIteratorOk("\"a\"\"b\"", 1, &[_][]const u8{"ab"}); 310 try testShellIteratorOk("\"a\"\"b\"", 1, &.{"ab"});
311 testShellIteratorOk("'a''b'", 1, &[_][]const u8{"ab"}); 311 try testShellIteratorOk("'a''b'", 1, &.{"ab"});
312 testShellIteratorOk("'a'b", 1, &[_][]const u8{"ab"}); 312 try testShellIteratorOk("'a'b", 1, &.{"ab"});
313 testShellIteratorOk("a'b'", 1, &[_][]const u8{"ab"}); 313 try testShellIteratorOk("a'b'", 1, &.{"ab"});
314 testShellIteratorOk("a\\ b", 1, &[_][]const u8{"a b"}); 314 try testShellIteratorOk("a\\ b", 1, &.{"a b"});
315 testShellIteratorOk("\"a\\ b\"", 1, &[_][]const u8{"a b"}); 315 try testShellIteratorOk("\"a\\ b\"", 1, &.{"a b"});
316 testShellIteratorOk("'a\\ b'", 0, &[_][]const u8{"a\\ b"}); 316 try testShellIteratorOk("'a\\ b'", 0, &.{"a\\ b"});
317 testShellIteratorOk(" a b ", 0, &[_][]const u8{ "a", "b" }); 317 try testShellIteratorOk(" a b ", 0, &.{ "a", "b" });
318 testShellIteratorOk("\\ \\ ", 0, &[_][]const u8{ " ", " " }); 318 try testShellIteratorOk("\\ \\ ", 0, &.{ " ", " " });
319 319
320 testShellIteratorOk( 320 try testShellIteratorOk(
321 \\printf 'run\nuninstall\n' 321 \\printf 'run\nuninstall\n'
322 , 0, &[_][]const u8{ "printf", "run\\nuninstall\\n" }); 322 , 0, &.{ "printf", "run\\nuninstall\\n" });
323 testShellIteratorOk( 323 try testShellIteratorOk(
324 \\setsid -f steam "steam://$action/$id" 324 \\setsid -f steam "steam://$action/$id"
325 , 0, &[_][]const u8{ "setsid", "-f", "steam", "steam://$action/$id" }); 325 , 0, &.{ "setsid", "-f", "steam", "steam://$action/$id" });
326 testShellIteratorOk( 326 try testShellIteratorOk(
327 \\xargs -I% rg --no-heading --no-line-number --only-matching 327 \\xargs -I% rg --no-heading --no-line-number --only-matching
328 \\ --case-sensitive --multiline --text --byte-offset '(?-u)%' $@ 328 \\ --case-sensitive --multiline --text --byte-offset '(?-u)%' $@
329 \\ 329 \\
330 , 0, &[_][]const u8{ 330 , 0, &.{
331 "xargs", "-I%", "rg", "--no-heading", 331 "xargs", "-I%", "rg", "--no-heading",
332 "--no-line-number", "--only-matching", "--case-sensitive", "--multiline", 332 "--no-line-number", "--only-matching", "--case-sensitive", "--multiline",
333 "--text", "--byte-offset", "(?-u)%", "$@", 333 "--text", "--byte-offset", "(?-u)%", "$@",
334 }); 334 });
335 335
336 testShellIteratorErr("'a", error.QuoteNotClosed); 336 try testShellIteratorErr("'a", error.QuoteNotClosed);
337 testShellIteratorErr("'a\\", error.QuoteNotClosed); 337 try testShellIteratorErr("'a\\", error.QuoteNotClosed);
338 testShellIteratorErr("\"a", error.QuoteNotClosed); 338 try testShellIteratorErr("\"a", error.QuoteNotClosed);
339 testShellIteratorErr("\"a\\", error.QuoteNotClosed); 339 try testShellIteratorErr("\"a\\", error.QuoteNotClosed);
340 testShellIteratorErr("a\\", error.DanglingEscape); 340 try testShellIteratorErr("a\\", error.DanglingEscape);
341} 341}