Summary: There are about 40 callsites to these across a couple of projects, and they seem generally useful.
Test Plan: ```fbconfig folly/experimental/test && fbmake runtests```
Reviewed By: yfeldblum@fb.com
Subscribers: folly-diffs@, yfeldblum
FB internal diff:
D1933415
Signature: t1:
1933415:
1427345307:
6587eea3dac74c5d841950ace3c3501d6e3dbe4a
#include <sys/stat.h>
#include <fcntl.h>
+#include <boost/regex.hpp>
#include <folly/Conv.h>
#include <folly/Exception.h>
return path;
}
-} // namespce
+} // namespace
TemporaryFile::TemporaryFile(StringPiece namePrefix,
fs::path dir,
::chdir(p.c_str());
}
+namespace detail {
+
+bool hasPCREPatternMatch(StringPiece pattern, StringPiece target) {
+ return boost::regex_match(
+ target.begin(),
+ target.end(),
+ boost::regex(pattern.begin(), pattern.end())
+ );
+}
+
+bool hasNoPCREPatternMatch(StringPiece pattern, StringPiece target) {
+ return !hasPCREPatternMatch(pattern, target);
+}
+
+} // namespace detail
+
} // namespace test
} // namespace folly
TemporaryDirectory dir_;
};
+/**
+ * Easy PCRE regex matching. Note that pattern must match the ENTIRE target,
+ * so use .* at the start and end of the pattern, as appropriate. See
+ * http://regex101.com/ for a PCRE simulator.
+ */
+#define EXPECT_PCRE_MATCH(pattern_stringpiece, target_stringpiece) \
+ EXPECT_PRED2( \
+ ::folly::test::detail::hasPCREPatternMatch, \
+ pattern_stringpiece, \
+ target_stringpiece \
+ )
+#define EXPECT_NO_PCRE_MATCH(pattern_stringpiece, target_stringpiece) \
+ EXPECT_PRED2( \
+ ::folly::test::detail::hasNoPCREPatternMatch, \
+ pattern_stringpiece, \
+ target_stringpiece \
+ )
+
+namespace detail {
+ bool hasPCREPatternMatch(StringPiece pattern, StringPiece target);
+ bool hasNoPCREPatternMatch(StringPiece pattern, StringPiece target);
+} // namespace detail
+
} // namespace test
} // namespace folly
EXPECT_EQ(pwd1, fs::current_path());
}
+TEST(PCREPatternMatch, Simple) {
+ EXPECT_PCRE_MATCH(".*a.c.*", "gabca");
+ EXPECT_NO_PCRE_MATCH("a.c", "gabca");
+ EXPECT_NO_PCRE_MATCH(".*ac.*", "gabca");
+}
+
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);