%description: Tests MatchExpression class. %includes: #include %global: using namespace omnetpp::common; static bool dottedpath; static bool fullstring; static bool casesensitive; static void match(const char *pattern, const char *line) { EV << pattern << " | " << line << " --> "; try { MatchExpression me(pattern, dottedpath, fullstring, casesensitive); MatchableString lineObject(line); bool result = me.matches(&lineObject); EV << (result?"true":"false") << "\n"; } catch (std::exception& e) { EV << "ERROR\n"; } } %activity: dottedpath = true; fullstring = true; casesensitive = true; // // Basic stuff, AND, OR, NOT // match("a", "a"); match("a", "b"); match("not a", "a"); match("not a", "b"); match("a OR b", "a"); match("b OR a", "a"); match("a OR b", "c"); match("{50..120} OR bu*bu", "bu--bu"); match("{50..120} OR bu*bu", "73"); match("{50..120} OR bu*bu", "120"); match("{50..120} OR bu*bu", "50"); match("{50..120} OR bu*bu", "500"); match("{50..120} OR bu*bu", "bu"); // OR is optional ("a b" means the same as "a OR b") match("a b c d", "c"); match("a b c d", "x"); match("a NOT b c", "b"); // read: "a OR (NOT b) OR c" match("a NOT b c", "c"); EV << endl; // // Precedence: AND binds stronger than OR, NOT binds strongest // match("(*one OR *two) AND twenty*", "twenty-one"); match("(*one OR *two) AND twenty*", "twenty-two"); match("(*one OR *two) AND twenty*", "twenty-three"); match("(*one OR *two) AND twenty*", "twenty-one"); match("(*one OR *two) AND twenty*", "thirty-one"); match("*one OR (*two AND twenty*)", "twenty-two"); match("*one OR (*two AND twenty*)", "thirty-one"); match("*one OR *two AND twenty*", "thirty-one"); // OR is optional match("twenty* AND *two thirty* AND *three", "thirty-three"); // read: "(twenty* AND *two) OR (thirty* AND *three)" match("twenty* AND *two thirty* AND *three", "thirty-two"); EV << endl; // // Quotes // match("\"a\"", "a"); match("\"a\"", "b"); match("\"*\"", "whatever"); EV << endl; // // Parsing // match("*or*", "whatever"); match("*and*", "whatever"); match("*not*", "whatever"); match("*not*", "knotty"); match("or*", "whatever"); match("and*", "whatever"); match("not*", "whatever"); match("*or", "whatever"); match("*and", "whatever"); match("*not", "whatever"); match("or", "whatever"); // parse error match("and", "whatever"); // parse error match("not", "whatever"); // parse error EV << endl; match("hi(there", "a"); // parse error match("\"hi(there\"", "hi(there"); match("a or(b and c)", "a"); EV << endl; EV << "done\n"; %exitcode: 0 %contains: stdout a | a --> true a | b --> false not a | a --> false not a | b --> true a OR b | a --> true b OR a | a --> true a OR b | c --> false {50..120} OR bu*bu | bu--bu --> true {50..120} OR bu*bu | 73 --> true {50..120} OR bu*bu | 120 --> true {50..120} OR bu*bu | 50 --> true {50..120} OR bu*bu | 500 --> false {50..120} OR bu*bu | bu --> false a b c d | c --> true a b c d | x --> false a NOT b c | b --> false a NOT b c | c --> true (*one OR *two) AND twenty* | twenty-one --> true (*one OR *two) AND twenty* | twenty-two --> true (*one OR *two) AND twenty* | twenty-three --> false (*one OR *two) AND twenty* | twenty-one --> true (*one OR *two) AND twenty* | thirty-one --> false *one OR (*two AND twenty*) | twenty-two --> true *one OR (*two AND twenty*) | thirty-one --> true *one OR *two AND twenty* | thirty-one --> true twenty* AND *two thirty* AND *three | thirty-three --> true twenty* AND *two thirty* AND *three | thirty-two --> false "a" | a --> true "a" | b --> false "*" | whatever --> true *or* | whatever --> false *and* | whatever --> false *not* | whatever --> false *not* | knotty --> true or* | whatever --> false and* | whatever --> false not* | whatever --> false *or | whatever --> false *and | whatever --> false *not | whatever --> false or | whatever --> ERROR and | whatever --> ERROR not | whatever --> ERROR hi(there | a --> ERROR "hi(there" | hi(there --> true a or(b and c) | a --> true done