1 | //===-- NameMatchesTest.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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "lldb/Utility/NameMatches.h" |
10 | #include "gtest/gtest.h" |
11 | |
12 | using namespace lldb_private; |
13 | |
14 | TEST(NameMatchesTest, Ignore) { |
15 | EXPECT_TRUE(NameMatches("foo" , NameMatch::Ignore, "bar" )); |
16 | } |
17 | |
18 | TEST(NameMatchesTest, Equals) { |
19 | EXPECT_TRUE(NameMatches("foo" , NameMatch::Equals, "foo" )); |
20 | EXPECT_FALSE(NameMatches("foo" , NameMatch::Equals, "bar" )); |
21 | } |
22 | |
23 | TEST(NameMatchesTest, Contains) { |
24 | EXPECT_TRUE(NameMatches("foobar" , NameMatch::Contains, "foo" )); |
25 | EXPECT_TRUE(NameMatches("foobar" , NameMatch::Contains, "oob" )); |
26 | EXPECT_TRUE(NameMatches("foobar" , NameMatch::Contains, "bar" )); |
27 | EXPECT_TRUE(NameMatches("foobar" , NameMatch::Contains, "foobar" )); |
28 | EXPECT_TRUE(NameMatches("" , NameMatch::Contains, "" )); |
29 | EXPECT_FALSE(NameMatches("" , NameMatch::Contains, "foo" )); |
30 | EXPECT_FALSE(NameMatches("foobar" , NameMatch::Contains, "baz" )); |
31 | } |
32 | |
33 | TEST(NameMatchesTest, StartsWith) { |
34 | EXPECT_TRUE(NameMatches("foo" , NameMatch::StartsWith, "f" )); |
35 | EXPECT_TRUE(NameMatches("foo" , NameMatch::StartsWith, "" )); |
36 | EXPECT_TRUE(NameMatches("" , NameMatch::StartsWith, "" )); |
37 | EXPECT_FALSE(NameMatches("foo" , NameMatch::StartsWith, "b" )); |
38 | EXPECT_FALSE(NameMatches("" , NameMatch::StartsWith, "b" )); |
39 | } |
40 | |
41 | TEST(NameMatchesTest, EndsWith) { |
42 | EXPECT_TRUE(NameMatches("foo" , NameMatch::EndsWith, "o" )); |
43 | EXPECT_TRUE(NameMatches("foo" , NameMatch::EndsWith, "" )); |
44 | EXPECT_TRUE(NameMatches("" , NameMatch::EndsWith, "" )); |
45 | EXPECT_FALSE(NameMatches("foo" , NameMatch::EndsWith, "b" )); |
46 | EXPECT_FALSE(NameMatches("" , NameMatch::EndsWith, "b" )); |
47 | } |
48 | |
49 | TEST(NameMatchesTest, RegularExpression) { |
50 | EXPECT_TRUE(NameMatches("foobar" , NameMatch::RegularExpression, "foo" )); |
51 | EXPECT_TRUE(NameMatches("foobar" , NameMatch::RegularExpression, "f[oa]o" )); |
52 | EXPECT_FALSE(NameMatches("foo" , NameMatch::RegularExpression, "" )); |
53 | EXPECT_FALSE(NameMatches("" , NameMatch::RegularExpression, "" )); |
54 | EXPECT_FALSE(NameMatches("foo" , NameMatch::RegularExpression, "b" )); |
55 | EXPECT_FALSE(NameMatches("" , NameMatch::RegularExpression, "b" )); |
56 | EXPECT_FALSE(NameMatches("^a" , NameMatch::RegularExpression, "^a" )); |
57 | } |
58 | |