[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Interpreter / TestRegexCommand.cpp
blobee30faab4814b27670bba4ddc5e2b9c458bc1ec1
1 //===-- TestRegexCommand.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 "Commands/CommandObjectRegexCommand.h"
10 #include "llvm/Testing/Support/Error.h"
11 #include "gtest/gtest.h"
13 using namespace lldb_private;
14 using namespace lldb;
16 namespace {
17 class TestRegexCommand : public CommandObjectRegexCommand {
18 public:
19 using CommandObjectRegexCommand::SubstituteVariables;
21 static std::string
22 Substitute(llvm::StringRef input,
23 const llvm::SmallVectorImpl<llvm::StringRef> &replacements) {
24 llvm::Expected<std::string> str = SubstituteVariables(input, replacements);
25 if (!str)
26 return llvm::toString(str.takeError());
27 return *str;
30 } // namespace
32 TEST(RegexCommandTest, SubstituteVariablesSuccess) {
33 const llvm::SmallVector<llvm::StringRef, 4> substitutions = {"all", "foo",
34 "bar", "baz"};
36 EXPECT_EQ(TestRegexCommand::Substitute("%0", substitutions), "all");
37 EXPECT_EQ(TestRegexCommand::Substitute("%1", substitutions), "foo");
38 EXPECT_EQ(TestRegexCommand::Substitute("%2", substitutions), "bar");
39 EXPECT_EQ(TestRegexCommand::Substitute("%3", substitutions), "baz");
40 EXPECT_EQ(TestRegexCommand::Substitute("%1%2%3", substitutions), "foobarbaz");
41 EXPECT_EQ(TestRegexCommand::Substitute("#%1#%2#%3#", substitutions),
42 "#foo#bar#baz#");
45 TEST(RegexCommandTest, SubstituteVariablesFailed) {
46 const llvm::SmallVector<llvm::StringRef, 4> substitutions = {"all", "foo",
47 "bar", "baz"};
49 ASSERT_THAT_EXPECTED(
50 TestRegexCommand::SubstituteVariables("%1%2%3%4", substitutions),
51 llvm::Failed());
52 ASSERT_THAT_EXPECTED(
53 TestRegexCommand::SubstituteVariables("%5", substitutions),
54 llvm::Failed());
55 ASSERT_THAT_EXPECTED(
56 TestRegexCommand::SubstituteVariables("%11", substitutions),
57 llvm::Failed());
60 TEST(RegexCommandTest, SubstituteVariablesNoRecursion) {
61 const llvm::SmallVector<llvm::StringRef, 4> substitutions = {"all", "%2",
62 "%3", "%4"};
63 EXPECT_EQ(TestRegexCommand::Substitute("%0", substitutions), "all");
64 EXPECT_EQ(TestRegexCommand::Substitute("%1", substitutions), "%2");
65 EXPECT_EQ(TestRegexCommand::Substitute("%2", substitutions), "%3");
66 EXPECT_EQ(TestRegexCommand::Substitute("%3", substitutions), "%4");
67 EXPECT_EQ(TestRegexCommand::Substitute("%1%2%3", substitutions), "%2%3%4");