Exemple #1
0
void Test__Parser__SimpleOptions() {
    /**************************************************************************+
     *                             OPTION
     *                            /      \
     *                           /        \
     *                          /          \
     *                         /       Without default
     *                        /                \
     *                       /                  \
     *                 Has default               \
     *                  /      \              -o some_val
     *                 /        \             -o "some spaced val"
     *                /          \            -o=some_val
     *               /            \           -o="some spaced val"
     *          -o, --opt        -o=some_val
     *        (default used)     -o="some spaced val"
     *                             (default overridden)
     **************************************************************************/

    Pattern pattern;
    PatternBuilder(pattern).opt("-o").opt("--opt").opt("-O").opt("--Opt");

    const char *argv[] = {"/path/to/bin",
                          "-o", "123",
                          "--opt 123 456",
                          "-O=123",
                          "--Opt=123 456"
                         };
    CmdLineParams params = pattern.match(static_cast<int>(sizeOfArray(argv)),
                                         const_cast<char **>(argv));
    ASSERT(false);
}
Exemple #2
0
void Test__Parser__SimpleFlags() {
    Pattern pattern;
    PatternBuilder(pattern).flag("-f").flag("--foo").flag("--bar");

    const char *argv[] = {"/path/to/bin", "-f", "--foo"};
    CmdLineParams params = pattern.match(static_cast<int>(sizeOfArray(argv)),
                                         const_cast<char **>(argv));
    ASSERT(params.hasFlag("-f"));
    ASSERT(params.hasFlag("--foo"));
    ASSERT(!params.hasFlag("--bar"));
    ASSERT_THROWS(params.hasFlag("--foobar"), UnknownParamException);
}
Exemple #3
0
void Test__Parser__SimpleArgs() {
    Pattern pattern;
    PatternBuilder(pattern).arg("arg0").arg().arg("arg2");

    const char *argv[] = {"/path/to/bin", "param0", "param1", "param2"};
    CmdLineParams params = pattern.match(static_cast<int>(sizeOfArray(argv)),
                                         const_cast<char **>(argv));

    ASSERT_EQ(str_t("param0"), str_t(params.getArg(0)));
    ASSERT_EQ(str_t("param0"), str_t(params.getArg("arg0")));

    ASSERT_EQ(str_t("param1"), str_t(params.getArg(1)));
    ASSERT_THROWS(params.getArg("arg1"), UnknownParamException);

    ASSERT_EQ(str_t("param2"), str_t(params.getArg(2)));
    ASSERT_EQ(str_t("param2"), str_t(params.getArg("arg2")));

    ASSERT_THROWS(params.getArg(3), UnknownParamException);
}
Exemple #4
0
bool BlockPattern::internalMatch(Pattern& reg, const QString & text) {
    return reg.match(text);
}