diff options
author | Matt Beaumont-Gay <matthewbg@google.com> | 2012-12-14 17:55:15 +0000 |
---|---|---|
committer | Matt Beaumont-Gay <matthewbg@google.com> | 2012-12-14 17:55:15 +0000 |
commit | 6aed25d93d1cfcde5809a73ffa7dc1b0d6396f66 (patch) | |
tree | 57e2fdf1caf960d8d878e0289f32af6759832b49 /unittests/Support/RegexTest.cpp | |
parent | 7139cfb19b1cc28dfd5e274c07ec68835bc6d6d6 (diff) | |
parent | 1ad9253c9d34ccbce3e7e4ea5d87c266cbf93410 (diff) |
Updating branches/google/stable to r169803
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/google/stable@170212 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support/RegexTest.cpp')
-rw-r--r-- | unittests/Support/RegexTest.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/unittests/Support/RegexTest.cpp b/unittests/Support/RegexTest.cpp index 65b66c3eee..3577d1015e 100644 --- a/unittests/Support/RegexTest.cpp +++ b/unittests/Support/RegexTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/Support/Regex.h" #include "llvm/ADT/SmallVector.h" +#include "gtest/gtest.h" #include <cstring> using namespace llvm; @@ -51,7 +51,6 @@ TEST_F(RegexTest, Basics) { EXPECT_EQ(1u, Matches.size()); EXPECT_EQ(String, Matches[0].str()); - std::string NulPattern="X[0-9]+X([a-f])?:([0-9]+)"; String="YX99a:513b"; NulPattern[7] = '\0'; @@ -62,6 +61,28 @@ TEST_F(RegexTest, Basics) { EXPECT_TRUE(r5.match(String)); } +TEST_F(RegexTest, Backreferences) { + Regex r1("([a-z]+)_\\1"); + SmallVector<StringRef, 4> Matches; + EXPECT_TRUE(r1.match("abc_abc", &Matches)); + EXPECT_EQ(2u, Matches.size()); + EXPECT_FALSE(r1.match("abc_ab", &Matches)); + + Regex r2("a([0-9])b\\1c\\1"); + EXPECT_TRUE(r2.match("a4b4c4", &Matches)); + EXPECT_EQ(2u, Matches.size()); + EXPECT_EQ("4", Matches[1].str()); + EXPECT_FALSE(r2.match("a2b2c3")); + + Regex r3("a([0-9])([a-z])b\\1\\2"); + EXPECT_TRUE(r3.match("a6zb6z", &Matches)); + EXPECT_EQ(3u, Matches.size()); + EXPECT_EQ("6", Matches[1].str()); + EXPECT_EQ("z", Matches[2].str()); + EXPECT_FALSE(r3.match("a6zb6y")); + EXPECT_FALSE(r3.match("a6zb7z")); +} + TEST_F(RegexTest, Substitution) { std::string Error; |