Hello everyone!
Making my parsing library I’ve decided to have two parse functions
parseArgs(gpa: Allocator, definition: anytype, args: []const []const u8, ...)for a very freestyle parsing. As I have to iterate over the arguments lots of times, the function requiresargsto be provided as inconst args = init.minimal.args.toSlice(init.gpa). To test it is no problem, I just declare aconst args = &[_][]u8{ "utility", "arg1", "--flag" }and I test it.- A POSIX style
parseArgsPosix(definition: anytype, args: *Args.Iterator, ...). Here is the question:
Is there someway to create the Args.Iterator object in the test itself given a string as it would be obtained from argv? Like this:
test "posix parses test" {
const def = .{
.options = .{ Opt(u64, "port", "p", 8080, "Port to connect") },
.flags = .{ Flag("verbose", "v", "Print details") },
};
const args = createIterator("utility -v -p 100");
const arguments = parseValuePosix(def, args, nullout, nullout);
// your tests here
}
I’ve take a look at the std.process.Args, and I’ve found the IteratorGeneral, but that’s not a *Args.Iterator type so it’s not exactly what I am looking for, and if would like to avoid changing the type of args to anytype and maybe both would work? Also, if to ask for an Iterator is not what I should do, feel free to tell me ![]()
Thank you!