1 //===- llvm/unittest/Support/RegexTest.cpp - Regex tests --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/Support/Regex.h"
12 #include "llvm/ADT/SmallVector.h"
18 class RegexTest : public ::testing::Test {
21 TEST_F(RegexTest, Basics) {
23 EXPECT_TRUE(r1.match("916"));
24 EXPECT_TRUE(r1.match("9"));
25 EXPECT_FALSE(r1.match("9a"));
27 SmallVector<StringRef, 1> Matches;
29 EXPECT_TRUE(r2.match("aa216b", &Matches));
30 EXPECT_EQ(1u, Matches.size());
31 EXPECT_EQ("216", Matches[0].str());
33 Regex r3("[0-9]+([a-f])?:([0-9]+)");
34 EXPECT_TRUE(r3.match("9a:513b", &Matches));
35 EXPECT_EQ(3u, Matches.size());
36 EXPECT_EQ("9a:513", Matches[0].str());
37 EXPECT_EQ("a", Matches[1].str());
38 EXPECT_EQ("513", Matches[2].str());
40 EXPECT_TRUE(r3.match("9:513b", &Matches));
41 EXPECT_EQ(3u, Matches.size());
42 EXPECT_EQ("9:513", Matches[0].str());
43 EXPECT_EQ("", Matches[1].str());
44 EXPECT_EQ("513", Matches[2].str());
47 std::string String="axxb";
49 EXPECT_FALSE(r4.match("abb"));
50 EXPECT_TRUE(r4.match(String, &Matches));
51 EXPECT_EQ(1u, Matches.size());
52 EXPECT_EQ(String, Matches[0].str());
55 std::string NulPattern="X[0-9]+X([a-f])?:([0-9]+)";
59 EXPECT_FALSE(r5.match(String));
60 EXPECT_FALSE(r5.match("X9"));
62 EXPECT_TRUE(r5.match(String));