• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef BASE_TESTING_TESTUTILS_H_
2 #define BASE_TESTING_TESTUTILS_H_
3 
4 #include <gmock/gmock.h>
5 
6 #include <regex>
7 #include <string>
8 
9 // The original gtest MatchesRegex will use different regex implementation on different platforms,
10 // e.g. on Windows gtest's limited regex engine is used while on Linux Posix ERE is used, which
11 // could result incompatible syntaxes. See
12 // https://github.com/google/googletest/blob/main/docs/advanced.md#regular-expression-syntax for
13 // details. std::regex will by default use the ECMAScript syntax for all platforms, which could fix
14 // this issue.
15 MATCHER_P(MatchesStdRegex, regStr, std::string("contains regular expression: ") + regStr) {
16     std::regex reg(regStr);
17     return std::regex_search(arg, reg);
18 }
19 
20 #endif  // BASE_TESTING_TESTUTILS_H_
21