[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Utility / RegularExpressionTest.cpp
blob4ac8f4953aab88a67e8a0b734e9b9fec4f49e237
1 //===-- RegularExpressionTest.cpp -----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/RegularExpression.h"
10 #include "llvm/ADT/SmallVector.h"
11 #include "gtest/gtest.h"
13 using namespace lldb_private;
14 using namespace llvm;
16 TEST(RegularExpression, Valid) {
17 RegularExpression r1("^[0-9]+$");
18 cantFail(r1.GetError());
19 EXPECT_TRUE(r1.IsValid());
20 EXPECT_EQ("^[0-9]+$", r1.GetText());
21 EXPECT_TRUE(r1.Execute("916"));
24 TEST(RegularExpression, CopyAssignment) {
25 RegularExpression r1("^[0-9]+$");
26 RegularExpression r2 = r1;
27 cantFail(r2.GetError());
28 EXPECT_TRUE(r2.IsValid());
29 EXPECT_EQ("^[0-9]+$", r2.GetText());
30 EXPECT_TRUE(r2.Execute("916"));
33 TEST(RegularExpression, Empty) {
34 RegularExpression r1("");
35 Error err = r1.GetError();
36 EXPECT_TRUE(static_cast<bool>(err));
37 consumeError(std::move(err));
38 EXPECT_FALSE(r1.IsValid());
39 EXPECT_EQ("", r1.GetText());
40 EXPECT_FALSE(r1.Execute("916"));
43 TEST(RegularExpression, Invalid) {
44 RegularExpression r1("a[b-");
45 Error err = r1.GetError();
46 EXPECT_TRUE(static_cast<bool>(err));
47 consumeError(std::move(err));
48 EXPECT_FALSE(r1.IsValid());
49 EXPECT_EQ("a[b-", r1.GetText());
50 EXPECT_FALSE(r1.Execute("ab"));
53 TEST(RegularExpression, Match) {
54 RegularExpression r1("[0-9]+([a-f])?:([0-9]+)");
55 cantFail(r1.GetError());
56 EXPECT_TRUE(r1.IsValid());
57 EXPECT_EQ("[0-9]+([a-f])?:([0-9]+)", r1.GetText());
59 SmallVector<StringRef, 3> matches;
60 EXPECT_TRUE(r1.Execute("9a:513b", &matches));
61 EXPECT_EQ(3u, matches.size());
62 EXPECT_EQ("9a:513", matches[0].str());
63 EXPECT_EQ("a", matches[1].str());
64 EXPECT_EQ("513", matches[2].str());