From ae2d5063d760a6f383ca195d766e44e5f8bcc6ed Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Tue, 19 Jun 2018 14:29:29 +0200 Subject: Updated to newest version of zig --- build.zig | 5 +- src/core.zig | 65 +++++++++++++------------ src/extended.zig | 51 +++++++++----------- tests/core.zig | 136 ++++++++++++++++++++++++----------------------------- tests/extended.zig | 68 +++++++++++++-------------- 5 files changed, 148 insertions(+), 177 deletions(-) diff --git a/build.zig b/build.zig index 29792ee..6ec8837 100644 --- a/build.zig +++ b/build.zig @@ -5,7 +5,7 @@ pub fn build(b: *Builder) void { { const example_step = b.step("examples", "Build all examples"); - const examples = [][]const u8 {}; + const examples = [][]const u8{}; b.default_step.dependOn(example_step); inline for (examples) |example| { @@ -22,7 +22,7 @@ pub fn build(b: *Builder) void { { const test_step = b.step("tests", "Run all tests"); - const tests = [][]const u8 { + const tests = [][]const u8{ "core", "extended", }; @@ -38,6 +38,5 @@ pub fn build(b: *Builder) void { step.dependOn(&t.step); test_step.dependOn(step); } - } } diff --git a/src/core.zig b/src/core.zig index d870e8c..a0f794c 100644 --- a/src/core.zig +++ b/src/core.zig @@ -102,12 +102,10 @@ pub fn Param(comptime Id: type) type { pub fn init(id: Id, takes_value: bool, names: *const Names) Self { // Assert, that if the param have no name, then it has to take // a value. - debug.assert( - names.bare != null or + debug.assert(names.bare != null or names.long != null or names.short != null or - takes_value - ); + takes_value); return Self{ .id = id, @@ -127,7 +125,7 @@ pub fn Arg(comptime Id: type) type { value: ?[]const u8, pub fn init(param: *const Param(Id), value: ?[]const u8) Self { - return Self { + return Self{ .param = param, .value = value, }; @@ -141,7 +139,7 @@ pub fn ArgIterator(comptime E: type) type { const Self = this; const Error = E; - nextFn: fn(iter: *Self) Error!?[]const u8, + nextFn: fn (iter: *Self) Error!?[]const u8, pub fn next(iter: *Self) Error!?[]const u8 { return iter.nextFn(iter); @@ -159,12 +157,10 @@ pub const ArgSliceIterator = struct { iter: ArgIterator(Error), pub fn init(args: []const []const u8) ArgSliceIterator { - return ArgSliceIterator { + return ArgSliceIterator{ .args = args, .index = 0, - .iter = ArgIterator(Error) { - .nextFn = nextFn, - }, + .iter = ArgIterator(Error){ .nextFn = nextFn }, }; } @@ -188,12 +184,10 @@ pub const OsArgIterator = struct { iter: ArgIterator(Error), pub fn init(allocator: *mem.Allocator) OsArgIterator { - return OsArgIterator { + return OsArgIterator{ .arena = heap.ArenaAllocator.init(allocator), .args = os.args(), - .iter = ArgIterator(Error) { - .nextFn = nextFn, - }, + .iter = ArgIterator(Error){ .nextFn = nextFn }, }; } @@ -204,7 +198,7 @@ pub const OsArgIterator = struct { fn nextFn(iter: *ArgIterator(Error)) Error!?[]const u8 { const self = @fieldParentPtr(OsArgIterator, "iter", iter); if (builtin.os == builtin.Os.windows) { - return try self.args.next(self.allocator) ?? return null; + return try self.args.next(self.allocator) orelse return null; } else { return self.args.nextPosix(); } @@ -233,7 +227,7 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { state: State, pub fn init(params: []const Param(Id), iter: *ArgIterator(ArgError)) Self { - var res = Self { + var res = Self{ .params = params, .iter = iter, .state = State.Normal, @@ -245,7 +239,11 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { /// Get the next ::Arg that matches a ::Param. pub fn next(clap: *Self) !?Arg(Id) { const ArgInfo = struct { - const Kind = enum { Long, Short, Bare }; + const Kind = enum { + Long, + Short, + Bare, + }; arg: []const u8, kind: Kind, @@ -253,7 +251,7 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { switch (clap.state) { State.Normal => { - const full_arg = (try clap.iter.next()) ?? return null; + const full_arg = (try clap.iter.next()) orelse return null; const arg_info = blk: { var arg = full_arg; var kind = ArgInfo.Kind.Bare; @@ -271,7 +269,7 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { if (kind != ArgInfo.Kind.Long and arg.len == 0) return error.InvalidArgument; - break :blk ArgInfo { .arg = arg, .kind = kind }; + break :blk ArgInfo{ .arg = arg, .kind = kind }; }; const arg = arg_info.arg; @@ -279,16 +277,15 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { const eql_index = mem.indexOfScalar(u8, arg, '='); switch (kind) { - ArgInfo.Kind.Bare, - ArgInfo.Kind.Long => { + ArgInfo.Kind.Bare, ArgInfo.Kind.Long => { for (clap.params) |*param| { const match = switch (kind) { - ArgInfo.Kind.Bare => param.names.bare ?? continue, - ArgInfo.Kind.Long => param.names.long ?? continue, + ArgInfo.Kind.Bare => param.names.bare orelse continue, + ArgInfo.Kind.Long => param.names.long orelse continue, else => unreachable, }; const name = if (eql_index) |i| arg[0..i] else arg; - const maybe_value = if (eql_index) |i| arg[i + 1..] else null; + const maybe_value = if (eql_index) |i| arg[i + 1 ..] else null; if (!mem.eql(u8, name, match)) continue; @@ -303,14 +300,14 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { if (maybe_value) |v| break :blk v; - break :blk (try clap.iter.next()) ?? return error.MissingValue; + break :blk (try clap.iter.next()) orelse return error.MissingValue; }; return Arg(Id).init(param, value); } }, ArgInfo.Kind.Short => { - return try clap.chainging(State.Chaining { + return try clap.chainging(State.Chaining{ .arg = full_arg, .index = (full_arg.len - arg.len), }); @@ -340,7 +337,7 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { const next_index = index + 1; for (clap.params) |*param| { - const short = param.names.short ?? continue; + const short = param.names.short orelse continue; if (short != arg[index]) continue; @@ -349,10 +346,12 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { if (arg.len <= next_index or param.takes_value) { clap.state = State.Normal; } else { - clap.state = State { .Chaining = State.Chaining { - .arg = arg, - .index = next_index, - }}; + clap.state = State{ + .Chaining = State.Chaining{ + .arg = arg, + .index = next_index, + }, + }; } } @@ -360,12 +359,12 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { return Arg(Id).init(param, null); if (arg.len <= next_index) { - const value = (try clap.iter.next()) ?? return error.MissingValue; + const value = (try clap.iter.next()) orelse return error.MissingValue; return Arg(Id).init(param, value); } if (arg[next_index] == '=') { - return Arg(Id).init(param, arg[next_index + 1..]); + return Arg(Id).init(param, arg[next_index + 1 ..]); } return Arg(Id).init(param, arg[next_index..]); diff --git a/src/extended.zig b/src/extended.zig index ec8310e..09e91dd 100644 --- a/src/extended.zig +++ b/src/extended.zig @@ -1,12 +1,12 @@ pub const core = @import("core.zig"); const builtin = @import("builtin"); -const std = @import("std"); +const std = @import("std"); -const mem = std.mem; -const fmt = std.fmt; +const mem = std.mem; +const fmt = std.fmt; const debug = std.debug; -const io = std.io; +const io = std.io; const assert = debug.assert; @@ -92,7 +92,7 @@ pub const Parser = struct { func: UnsafeFunction, pub fn init(comptime FieldType: type, comptime Errors: type, func: ParseFunc(FieldType, Errors)) Parser { - return Parser { + return Parser{ .FieldType = FieldType, .Errors = Errors, .func = @ptrCast(UnsafeFunction, func), @@ -104,7 +104,7 @@ pub const Parser = struct { } fn ParseFunc(comptime FieldType: type, comptime Errors: type) type { - return fn(*FieldType, []const u8) Errors!void; + return fn (*FieldType, []const u8) Errors!void; } pub fn int(comptime Int: type, comptime radix: u8) Parser { @@ -113,22 +113,14 @@ pub const Parser = struct { field_ptr.* = try fmt.parseInt(Int, arg, radix); } }.i; - return Parser.init( - Int, - @typeOf(func).ReturnType.ErrorSet, - func - ); + return Parser.init(Int, @typeOf(func).ReturnType.ErrorSet, func); } - const string = Parser.init( - []const u8, - error{}, - struct { - fn s(field_ptr: *[]const u8, arg: []const u8) (error{}!void) { - field_ptr.* = arg; - } - }.s - ); + const string = Parser.init([]const u8, error{}, struct { + fn s(field_ptr: *[]const u8, arg: []const u8) (error{}!void) { + field_ptr.* = arg; + } + }.s); }; pub fn Clap(comptime Result: type) type { @@ -174,7 +166,7 @@ pub fn Clap(comptime Result: type) type { for (command.params) |p, i| { const id = i; - res[id] = core.Param(usize) { + res[id] = core.Param(usize){ .id = id, .takes_value = p.kind == Param.Kind.Option, .names = p.names, @@ -186,10 +178,9 @@ pub fn Clap(comptime Result: type) type { var pos: usize = 0; - arg_loop: - while (try clap.next()) |arg| : (pos += 1) { - inline for(command.params) |param, i| { - if (arg.param.id == i and (param.settings.position ?? pos) == pos) { + arg_loop: while (try clap.next()) |arg| : (pos += 1) { + inline for (command.params) |param, i| { + if (arg.param.id == i and (param.settings.position orelse pos) == pos) { handled[i] = true; switch (param.kind) { @@ -197,7 +188,7 @@ pub fn Clap(comptime Result: type) type { getFieldPtr(&result, param.field).* = true; }, Param.Kind.Option => |parser| { - try parser.parse(getFieldPtr(&result, param.field), ??arg.value); + try parser.parse(getFieldPtr(&result, param.field), arg.value.?); }, Param.Kind.Subcommand => |sub_command| { getFieldPtr(&result, param.field).* = try sub_command.parseHelper(Error, clap); @@ -223,19 +214,19 @@ pub fn Clap(comptime Result: type) type { fn GetFieldPtrReturn(comptime Struct: type, comptime field: []const u8) type { var inst: Struct = undefined; - const dot_index = comptime mem.indexOfScalar(u8, field, '.') ?? { + const dot_index = comptime mem.indexOfScalar(u8, field, '.') orelse { return @typeOf(&@field(inst, field)); }; - return GetFieldPtrReturn(@typeOf(@field(inst, field[0..dot_index])), field[dot_index + 1..]); + return GetFieldPtrReturn(@typeOf(@field(inst, field[0..dot_index])), field[dot_index + 1 ..]); } fn getFieldPtr(curr: var, comptime field: []const u8) GetFieldPtrReturn(@typeOf(curr).Child, field) { - const dot_index = comptime mem.indexOfScalar(u8, field, '.') ?? { + const dot_index = comptime mem.indexOfScalar(u8, field, '.') orelse { return &@field(curr, field); }; - return getFieldPtr(&@field(curr, field[0..dot_index]), field[dot_index + 1..]); + return getFieldPtr(&@field(curr, field[0..dot_index]), field[dot_index + 1 ..]); } }; } diff --git a/tests/core.zig b/tests/core.zig index 91b62fe..765b161 100644 --- a/tests/core.zig +++ b/tests/core.zig @@ -19,116 +19,102 @@ fn testNoErr(params: []const Param(u8), args: []const []const u8, ids: []const u var i: usize = 0; while (iter.next() catch unreachable) |arg| : (i += 1) { debug.assert(ids[i] == arg.param.id); - const expected_value = values[i] ?? { + const expected_value = values[i] orelse { debug.assert(arg.value == null); continue; }; - const actual_value = arg.value ?? unreachable; + const actual_value = arg.value orelse unreachable; debug.assert(mem.eql(u8, expected_value, actual_value)); } } test "clap.core: short" { - const params = []Param(u8) { + const params = []Param(u8){ Param(u8).init(0, false, Names.short('a')), Param(u8).init(1, false, Names.short('b')), - Param(u8).init(2, true, Names.short('c')), + Param(u8).init(2, true, Names.short('c')), }; - testNoErr(params, [][]const u8 { "-a" }, []u8{0}, []?[]const u8{null}); - testNoErr(params, [][]const u8 { "-a", "-b" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "-ab" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "-c=100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "-c100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "-c", "100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "-abc", "100" }, []u8{0,1,2}, []?[]const u8{null,null,"100"}); - testNoErr(params, [][]const u8 { "-abc=100" }, []u8{0,1,2}, []?[]const u8{null,null,"100"}); - testNoErr(params, [][]const u8 { "-abc100" }, []u8{0,1,2}, []?[]const u8{null,null,"100"}); + testNoErr(params, [][]const u8{"-a"}, []u8{0}, []?[]const u8{null}); + testNoErr(params, [][]const u8{ "-a", "-b" }, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"-ab"}, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"-c=100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{"-c100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "-c", "100" }, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "-abc", "100" }, []u8{ 0, 1, 2 }, []?[]const u8{ null, null, "100" }); + testNoErr(params, [][]const u8{"-abc=100"}, []u8{ 0, 1, 2 }, []?[]const u8{ null, null, "100" }); + testNoErr(params, [][]const u8{"-abc100"}, []u8{ 0, 1, 2 }, []?[]const u8{ null, null, "100" }); } test "clap.core: long" { - const params = []Param(u8) { + const params = []Param(u8){ Param(u8).init(0, false, Names.long("aa")), Param(u8).init(1, false, Names.long("bb")), - Param(u8).init(2, true, Names.long("cc")), + Param(u8).init(2, true, Names.long("cc")), }; - testNoErr(params, [][]const u8 { "--aa" }, []u8{0}, []?[]const u8{null}); - testNoErr(params, [][]const u8 { "--aa", "--bb" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "--cc=100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "--cc", "100" }, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{"--aa"}, []u8{0}, []?[]const u8{null}); + testNoErr(params, [][]const u8{ "--aa", "--bb" }, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"--cc=100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "--cc", "100" }, []u8{2}, []?[]const u8{"100"}); } test "clap.core: bare" { - const params = []Param(u8) { + const params = []Param(u8){ Param(u8).init(0, false, Names.bare("aa")), Param(u8).init(1, false, Names.bare("bb")), - Param(u8).init(2, true, Names.bare("cc")), + Param(u8).init(2, true, Names.bare("cc")), }; - testNoErr(params, [][]const u8 { "aa" }, []u8{0}, []?[]const u8{null}); - testNoErr(params, [][]const u8 { "aa", "bb" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "cc=100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "cc", "100" }, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{"aa"}, []u8{0}, []?[]const u8{null}); + testNoErr(params, [][]const u8{ "aa", "bb" }, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"cc=100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "cc", "100" }, []u8{2}, []?[]const u8{"100"}); } test "clap.core: none" { - const params = []Param(u8) { - Param(u8).init(0, true, Names.none()), - }; + const params = []Param(u8){Param(u8).init(0, true, Names.none())}; - testNoErr(params, [][]const u8 { "aa" }, []u8{0}, []?[]const u8{"aa"}); + testNoErr(params, [][]const u8{"aa"}, []u8{0}, []?[]const u8{"aa"}); } test "clap.core: all" { - const params = []Param(u8) { - Param(u8).init( - 0, - false, - Names{ - .bare = "aa", - .short = 'a', - .long = "aa", - } - ), - Param(u8).init( - 1, - false, - Names{ - .bare = "bb", - .short = 'b', - .long = "bb", - } - ), - Param(u8).init( - 2, - true, - Names{ - .bare = "cc", - .short = 'c', - .long = "cc", - } - ), + const params = []Param(u8){ + Param(u8).init(0, false, Names{ + .bare = "aa", + .short = 'a', + .long = "aa", + }), + Param(u8).init(1, false, Names{ + .bare = "bb", + .short = 'b', + .long = "bb", + }), + Param(u8).init(2, true, Names{ + .bare = "cc", + .short = 'c', + .long = "cc", + }), Param(u8).init(3, true, Names.none()), }; - testNoErr(params, [][]const u8 { "-a" }, []u8{0}, []?[]const u8{null}); - testNoErr(params, [][]const u8 { "-a", "-b" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "-ab" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "-c=100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "-c100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "-c", "100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "-abc", "100" }, []u8{0,1,2}, []?[]const u8{null,null,"100"}); - testNoErr(params, [][]const u8 { "-abc=100" }, []u8{0,1,2}, []?[]const u8{null,null,"100"}); - testNoErr(params, [][]const u8 { "-abc100" }, []u8{0,1,2}, []?[]const u8{null,null,"100"}); - testNoErr(params, [][]const u8 { "--aa" }, []u8{0}, []?[]const u8{null}); - testNoErr(params, [][]const u8 { "--aa", "--bb" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "--cc=100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "--cc", "100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "aa" }, []u8{0}, []?[]const u8{null}); - testNoErr(params, [][]const u8 { "aa", "bb" }, []u8{0,1}, []?[]const u8{null,null}); - testNoErr(params, [][]const u8 { "cc=100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "cc", "100" }, []u8{2}, []?[]const u8{"100"}); - testNoErr(params, [][]const u8 { "dd" }, []u8{3}, []?[]const u8{"dd"}); + testNoErr(params, [][]const u8{"-a"}, []u8{0}, []?[]const u8{null}); + testNoErr(params, [][]const u8{ "-a", "-b" }, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"-ab"}, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"-c=100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{"-c100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "-c", "100" }, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "-abc", "100" }, []u8{ 0, 1, 2 }, []?[]const u8{ null, null, "100" }); + testNoErr(params, [][]const u8{"-abc=100"}, []u8{ 0, 1, 2 }, []?[]const u8{ null, null, "100" }); + testNoErr(params, [][]const u8{"-abc100"}, []u8{ 0, 1, 2 }, []?[]const u8{ null, null, "100" }); + testNoErr(params, [][]const u8{"--aa"}, []u8{0}, []?[]const u8{null}); + testNoErr(params, [][]const u8{ "--aa", "--bb" }, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"--cc=100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "--cc", "100" }, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{"aa"}, []u8{0}, []?[]const u8{null}); + testNoErr(params, [][]const u8{ "aa", "bb" }, []u8{ 0, 1 }, []?[]const u8{ null, null }); + testNoErr(params, [][]const u8{"cc=100"}, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{ "cc", "100" }, []u8{2}, []?[]const u8{"100"}); + testNoErr(params, [][]const u8{"dd"}, []u8{3}, []?[]const u8{"dd"}); } diff --git a/tests/extended.zig b/tests/extended.zig index 78c319e..3dbb87d 100644 --- a/tests/extended.zig +++ b/tests/extended.zig @@ -29,18 +29,14 @@ pub fn Test(comptime Expect: type) type { pub fn success(args: []const []const u8, expected: *const Expect) Self { return Self{ .args = args, - .kind = Kind{ - .Success = expected.*, - }, + .kind = Kind{ .Success = expected.* }, }; } pub fn fail(args: []const []const u8, err: error) Self { return Self{ .args = args, - .kind = Kind{ - .Fail = err, - }, + .kind = Kind{ .Fail = err }, }; } @@ -86,74 +82,74 @@ test "clap.extended: short" { break :p res; }, Param.option("b", Names.short('b'), &Parser.int(u8, 10)), - } + }, }; const T = Test(S); const tests = []T{ T.success( - [][]const u8 { "-a" }, + [][]const u8{"-a"}, S{ .a = true, .b = 0, }, ), T.success( - [][]const u8 { "-a", "-b", "100" }, + [][]const u8{ "-a", "-b", "100" }, S{ .a = true, .b = 100, }, ), T.success( - [][]const u8 { "-a", "-b=100" }, + [][]const u8{ "-a", "-b=100" }, S{ .a = true, .b = 100, }, ), T.success( - [][]const u8 { "-a", "-b100" }, + [][]const u8{ "-a", "-b100" }, S{ .a = true, .b = 100, }, ), T.success( - [][]const u8 { "-ab", "100" }, + [][]const u8{ "-ab", "100" }, S{ .a = true, .b = 100, }, ), T.success( - [][]const u8 { "-ab=100" }, + [][]const u8{"-ab=100"}, S{ .a = true, .b = 100, }, ), T.success( - [][]const u8 { "-ab100" }, + [][]const u8{"-ab100"}, S{ .a = true, .b = 100, }, ), T.fail( - [][]const u8 { "-q" }, + [][]const u8{"-q"}, error.InvalidArgument, ), T.fail( - [][]const u8 { "--a" }, + [][]const u8{"--a"}, error.InvalidArgument, ), T.fail( - [][]const u8 { "-b=100" }, + [][]const u8{"-b=100"}, error.ParamNotHandled, ), T.fail( - [][]const u8 { "-b=100", "-a" }, + [][]const u8{ "-b=100", "-a" }, error.InvalidArgument, ), }; @@ -182,50 +178,50 @@ test "clap.extended: long" { break :p res; }, Param.option("b", Names.long('b'), &Parser.int(u8, 10)), - } + }, }; const T = Test(S); const tests = []T{ T.success( - [][]const u8 { "--a" }, + [][]const u8{"--a"}, S{ .a = true, .b = 0, }, ), T.success( - [][]const u8 { "--a", "--b", "100" }, + [][]const u8{ "--a", "--b", "100" }, S{ .a = true, .b = 100, }, ), T.success( - [][]const u8 { "--a", "--b=100" }, + [][]const u8{ "--a", "--b=100" }, S{ .a = true, .b = 100, }, ), T.fail( - [][]const u8 { "--a=100" }, + [][]const u8{"--a=100"}, error.DoesntTakeValue, ), T.fail( - [][]const u8 { "--q" }, + [][]const u8{"--q"}, error.InvalidArgument, ), T.fail( - [][]const u8 { "-a" }, + [][]const u8{"-a"}, error.InvalidArgument, ), T.fail( - [][]const u8 { "--b=100" }, + [][]const u8{"--b=100"}, error.ParamNotHandled, ), T.fail( - [][]const u8 { "--b=100", "--a" }, + [][]const u8{ "--b=100", "--a" }, error.InvalidArgument, ), }; @@ -254,50 +250,50 @@ test "clap.extended: bare" { break :p res; }, Param.option("b", Names.bare('b'), &Parser.int(u8, 10)), - } + }, }; const T = Test(S); const tests = []T{ T.success( - [][]const u8 { "a" }, + [][]const u8{"a"}, S{ .a = true, .b = 0, }, ), T.success( - [][]const u8 { "a", "b", "100" }, + [][]const u8{ "a", "b", "100" }, S{ .a = true, .b = 100, }, ), T.success( - [][]const u8 { "a", "b=100" }, + [][]const u8{ "a", "b=100" }, S{ .a = true, .b = 100, }, ), T.fail( - [][]const u8 { "a=100" }, + [][]const u8{"a=100"}, error.DoesntTakeValue, ), T.fail( - [][]const u8 { "--a" }, + [][]const u8{"--a"}, error.InvalidArgument, ), T.fail( - [][]const u8 { "-a" }, + [][]const u8{"-a"}, error.InvalidArgument, ), T.fail( - [][]const u8 { "b=100" }, + [][]const u8{"b=100"}, error.ParamNotHandled, ), T.fail( - [][]const u8 { "b=100", "--a" }, + [][]const u8{ "b=100", "--a" }, error.InvalidArgument, ), }; -- cgit v1.2.3