Open ronaldfenner opened 3 years ago
For me, it works with [0-9]
instead of \\d
(using current trunk build: a3460d1aeeaa43fdf137a6adefef10ba0b59fe4b)
I found this issue only appeared on Linux + gcc. \d works on Windows.
Also having this issue on 1.11, using [0-9]
fixed it but was unpleasant to debug
Same problem. EXPECT_THAT("name 1", MatchesRegex("name \\d+"));
fails!
\d+
works for me on Windows, but not [0-9]+
:(
As per the documentation, Windows works differently:
On Windows, GoogleTest uses its own simple regular expression implementation. It lacks many features. For example, we don't support union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and repetition count ("x{5,7}"), among others. Below is what we do support (A denotes a literal character, period (.), or a single \ escape sequence; x and y denote regular expressions.):
https://github.com/google/googletest/blob/main/docs/advanced.md#regular-expression-syntax
This is kind of annoying as \d+
is one of the examples: http://google.github.io/googletest/reference/assertions.html#EXPECT_THAT
Here is a testcase that fails due to this issue:
As as I get the SLA sorted out I'll open a MR. :-) Or anyone else may "reproduce" those few lines. ;)
I'm trying to to use MatchesRegEx to match a date but it always returns failed. I'm run this test on MacOS so it's a posix system but i'm just trying to use the simplified syntax so i don't have to have 2 versions.
The code I'm trying to use is
EXPECT_THAT(Log::GenerateISO8601Time(true), ::testing::MatchesRegex("\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ"));
I figured maybe it wasn't correct so i went to a simple test for just
EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex("\\d+"));
It also doesn't work.
This does work though
EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex("2020")); EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex(".+"));
I did browse through the chromium repo looking at its use of MatchesRegEx. I'm also using bazel as the build system so it build gtest as a dependency of the test.