From 9e2ac9c6ab567ab3d95db9527147ef80aa4dd7c1 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Tue, 13 Nov 2018 13:33:51 +0100 Subject: Zig fmt --- clap.zig | 25 +------------------------ test.zig | 54 ++++++++++++++++++++++++++---------------------------- 2 files changed, 27 insertions(+), 52 deletions(-) diff --git a/clap.zig b/clap.zig index 26b97aa..a2d30a5 100644 --- a/clap.zig +++ b/clap.zig @@ -210,7 +210,7 @@ pub const OsArgIterator = struct { /// ::StreamingClap.next to parse all the arguments of your program. pub fn StreamingClap(comptime Id: type, comptime ArgError: type) type { return struct { - const Self = @This(); + const Self = @This(); const State = union(enum) { Normal, @@ -374,26 +374,3 @@ pub fn StreamingClap(comptime Id: type, comptime ArgError: type) type { } }; } - -pub fn ToStructId(comptime T: type) type { - return struct { - parse: fn(*T, ?[]const u8) - }; -} - -const ToStructParamError = error{}; -const ToStructParam = Param(fn (*T, ?[]const u8) ToStructParamError!void); - -fn paramsFromStruct(comptime T: type) []const ToStructParam { - var res: []const ToStructParam = []ToStructParam{}; - - for (@typeInfo(T).Struct.fields) |field| { - res = res ++ []ToStructParam{ - ToStructParam.init() - }; - } -} - -pub fn toStruct(defaults: var, iter: *ArgIterator(ArgError)) !@typeOf(defaults) { - -} diff --git a/test.zig b/test.zig index 70bbab1..27c93c2 100644 --- a/test.zig +++ b/test.zig @@ -11,7 +11,7 @@ const Names = clap.Names; const Param = clap.Param(u8); const StreamingClap = clap.StreamingClap(u8, ArgSliceIterator.Error); const Arg = clap.Arg(u8); - + fn testNoErr(params: []const Param, args: []const []const u8, results: []const Arg) void { var arg_iter = ArgSliceIterator.init(args); var c = StreamingClap.init(params, &arg_iter.iter); @@ -26,7 +26,7 @@ fn testNoErr(params: []const Param, args: []const []const u8, results: []const A const actual_value = arg.value orelse unreachable; debug.assert(mem.eql(u8, expected_value, actual_value)); } - + if (c.next() catch unreachable) |_| { unreachable; } @@ -38,17 +38,17 @@ test "clap: short" { Param.init(1, false, Names.short('b')), Param.init(2, true, Names.short('c')), }; - + const a = ¶ms[0]; const b = ¶ms[1]; const c = ¶ms[2]; - + testNoErr( params, [][]const u8{ "-a", "-b", "-ab", "-ba", - "-c", "0", "-c=0", - "-ac", "0", "-ac=0", + "-c", "0", "-c=0", "-ac", + "0", "-ac=0", }, []const Arg{ Arg.init(a, null), @@ -73,16 +73,17 @@ test "clap: long" { Param.init(1, false, Names.long("bb")), Param.init(2, true, Names.long("cc")), }; - + const aa = ¶ms[0]; const bb = ¶ms[1]; const cc = ¶ms[2]; - + testNoErr( params, [][]const u8{ "--aa", "--bb", - "--cc", "0", "--cc=0", + "--cc", "0", + "--cc=0", }, []const Arg{ Arg.init(aa, null), @@ -99,16 +100,17 @@ test "clap: bare" { Param.init(1, false, Names.bare("bb")), Param.init(2, true, Names.bare("cc")), }; - + const aa = ¶ms[0]; const bb = ¶ms[1]; const cc = ¶ms[2]; - + testNoErr( params, [][]const u8{ "aa", "bb", - "cc", "0", "cc=0", + "cc", "0", + "cc=0", }, []const Arg{ Arg.init(aa, null), @@ -120,13 +122,11 @@ test "clap: bare" { } test "clap: none" { - const params = []Param{ - Param.init(0, true, Names.none()), - }; - + const params = []Param{Param.init(0, true, Names.none())}; + testNoErr( params, - [][]const u8{"aa", "bb"}, + [][]const u8{ "aa", "bb" }, []const Arg{ Arg.init(¶ms[0], "aa"), Arg.init(¶ms[0], "bb"), @@ -153,22 +153,20 @@ test "clap: all" { }), Param.init(3, true, Names.none()), }; - + const aa = ¶ms[0]; const bb = ¶ms[1]; const cc = ¶ms[2]; const bare = ¶ms[3]; - + testNoErr( params, [][]const u8{ "-a", "-b", "-ab", "-ba", - "-c", "0", "-c=0", - "-ac", "0", "-ac=0", - "--aa", "--bb", - "--cc", "0", "--cc=0", - "aa", "bb", - "cc", "0", "cc=0", + "-c", "0", "-c=0", "-ac", + "0", "-ac=0", "--aa", "--bb", + "--cc", "0", "--cc=0", "aa", + "bb", "cc", "0", "cc=0", "something", }, []const Arg{ @@ -217,9 +215,9 @@ test "clap.Example" { const params = []c.Param(u8){ c.Param(u8).init('h', false, c.Names.prefix("help")), c.Param(u8).init('v', false, c.Names.prefix("version")), - c.Param(u8).init('f', true, c.Names.none()), + c.Param(u8).init('f', true, c.Names.none()), }; - + // Here, we use an `ArgSliceIterator` which iterates over // a slice of arguments. For real program, you would probably // use `OsArgIterator`. @@ -244,4 +242,4 @@ test "clap.Example" { else => unreachable, } } -} \ No newline at end of file +} -- cgit v1.2.3