MCPcopy Create free account
hub / github.com/apache/trafficserver / main

Function main

plugins/cachekey/tests/pattern_test.cc:30–66  ·  view source on GitHub ↗

* @file pattern_test.cc * @brief simple test driver to test and experiment with PCRE patterns. * * @todo: create unit tests for the classes in pattern.cc. * Compile with -DCACHEKEY_UNIT_TEST to use non-ATS logging. */

Source from the content-addressed store, hash-verified

28 * Compile with -DCACHEKEY_UNIT_TEST to use non-ATS logging.
29 */
30int
31main(int argc, char *argv[])
32{
33 if (argc < 3) {
34 std::cerr << "Usage: " << String(argv[0]) << " subject pattern" << std::endl;
35 return -1;
36 }
37
38 String subject(argv[1]);
39 String pattern(argv[2]);
40
41 std::cout << "subject: '" << subject << "'" << std::endl;
42 std::cout << "pattern: '" << pattern << "'" << std::endl;
43
44 Pattern p;
45 if (p.init(pattern)) {
46 std::cout << "--- matching ---" << std::endl;
47 bool result = p.match(subject);
48 std::cout << "subject:'" << subject << "' " << (char *)(result ? "matched" : "did not match") << " pattern:'" << pattern << "'"
49 << std::endl;
50
51 std::cout << "--- capture ---" << std::endl;
52 StringVector v;
53 result = p.capture(subject, v);
54 for (StringVector::iterator it = v.begin(); it != v.end(); ++it) {
55 std::cout << "capture: " << *it << std::endl;
56 }
57
58 std::cout << "--- replace ---" << std::endl;
59 String r;
60 result = p.replace(subject, r);
61 std::cout << "replacement result:'" << result << "'" << std::endl;
62
63 } else {
64 std::cout << "pattern: '" << pattern << "' failed to compile" << std::endl;
65 }
66}

Callers

nothing calls this directly

Calls 7

StringClass · 0.50
initMethod · 0.45
matchMethod · 0.45
captureMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected