diff options
| author | 2018-03-14 14:17:48 +0100 | |
|---|---|---|
| committer | 2018-03-14 14:17:48 +0100 | |
| commit | 452efd977c118f44c9c62420ff15174902252382 (patch) | |
| tree | 350b7a75cd99afb8d95ee1e1a403e2f965e98ec1 /clap.zig | |
| parent | Added command line argument parser. (diff) | |
| download | zig-clap-452efd977c118f44c9c62420ff15174902252382.tar.gz zig-clap-452efd977c118f44c9c62420ff15174902252382.tar.xz zig-clap-452efd977c118f44c9c62420ff15174902252382.zip | |
Changed around some code in test
Diffstat (limited to 'clap.zig')
| -rw-r--r-- | clap.zig | 44 |
1 files changed, 23 insertions, 21 deletions
| @@ -260,26 +260,6 @@ test "clap.parse.Example" { | |||
| 260 | } | 260 | } |
| 261 | }; | 261 | }; |
| 262 | 262 | ||
| 263 | const COption = Option(Color, @typeOf(Color.rFromStr).ReturnType.ErrorSet); | ||
| 264 | const options = comptime []COption { | ||
| 265 | COption.init(Color.rFromStr) | ||
| 266 | .setHelp("The amount of red in our color") | ||
| 267 | .setShort('r') | ||
| 268 | .setLong("red") | ||
| 269 | .takesValue(true) | ||
| 270 | .setKind(COption.Kind.Required), | ||
| 271 | COption.init(Color.gFromStr) | ||
| 272 | .setHelp("The amount of green in our color") | ||
| 273 | .setShort('g') | ||
| 274 | .setLong("green") | ||
| 275 | .takesValue(true), | ||
| 276 | COption.init(Color.bFromStr) | ||
| 277 | .setHelp("The amount of blue in our color") | ||
| 278 | .setShort('b') | ||
| 279 | .setLong("blue") | ||
| 280 | .takesValue(true), | ||
| 281 | }; | ||
| 282 | |||
| 283 | const Case = struct { args: []const []const u8, res: Color, err: ?error }; | 263 | const Case = struct { args: []const []const u8, res: Color, err: ?error }; |
| 284 | const cases = []Case { | 264 | const cases = []Case { |
| 285 | Case { | 265 | Case { |
| @@ -319,7 +299,29 @@ test "clap.parse.Example" { | |||
| 319 | }, | 299 | }, |
| 320 | }; | 300 | }; |
| 321 | 301 | ||
| 322 | const Clap = Parser(Color, @typeOf(Color.rFromStr).ReturnType.ErrorSet, Color { .r = 0, .g = 0, .b = 0 }, options); | 302 | const COption = Option(Color, @typeOf(Color.rFromStr).ReturnType.ErrorSet); |
| 303 | const Clap = Parser(Color, @typeOf(Color.rFromStr).ReturnType.ErrorSet, | ||
| 304 | Color { .r = 0, .g = 0, .b = 0 }, | ||
| 305 | comptime []COption { | ||
| 306 | COption.init(Color.rFromStr) | ||
| 307 | .setHelp("The amount of red in our color") | ||
| 308 | .setShort('r') | ||
| 309 | .setLong("red") | ||
| 310 | .takesValue(true) | ||
| 311 | .setKind(COption.Kind.Required), | ||
| 312 | COption.init(Color.gFromStr) | ||
| 313 | .setHelp("The amount of green in our color") | ||
| 314 | .setShort('g') | ||
| 315 | .setLong("green") | ||
| 316 | .takesValue(true), | ||
| 317 | COption.init(Color.bFromStr) | ||
| 318 | .setHelp("The amount of blue in our color") | ||
| 319 | .setShort('b') | ||
| 320 | .setLong("blue") | ||
| 321 | .takesValue(true), | ||
| 322 | } | ||
| 323 | ); | ||
| 324 | |||
| 323 | for (cases) |case, i| { | 325 | for (cases) |case, i| { |
| 324 | if (Clap.parse(case.args)) |res| { | 326 | if (Clap.parse(case.args)) |res| { |
| 325 | assert(res.r == case.res.r); | 327 | assert(res.r == case.res.r); |