[llvm-nm] - Fix a bug and unbreak ASan BB.
[llvm-complete.git] / unittests / Support / GlobPatternTest.cpp
blob113b20e047eae67113c605e3a4ebcf1e6b16383a
1 //===- llvm/unittest/Support/GlobPatternTest.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 "llvm/Support/GlobPattern.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
13 namespace {
15 class GlobPatternTest : public ::testing::Test {};
17 TEST_F(GlobPatternTest, Basics) {
18 Expected<GlobPattern> Pat1 = GlobPattern::create("");
19 EXPECT_TRUE((bool)Pat1);
20 EXPECT_TRUE(Pat1->match(""));
21 EXPECT_FALSE(Pat1->match("a"));
23 Expected<GlobPattern> Pat2 = GlobPattern::create("ab*c*def");
24 EXPECT_TRUE((bool)Pat2);
25 EXPECT_TRUE(Pat2->match("abcdef"));
26 EXPECT_TRUE(Pat2->match("abxcxdef"));
27 EXPECT_FALSE(Pat2->match(""));
28 EXPECT_FALSE(Pat2->match("xabcdef"));
29 EXPECT_FALSE(Pat2->match("abcdefx"));
31 Expected<GlobPattern> Pat3 = GlobPattern::create("a??c");
32 EXPECT_TRUE((bool)Pat3);
33 EXPECT_TRUE(Pat3->match("axxc"));
34 EXPECT_FALSE(Pat3->match("axxx"));
35 EXPECT_FALSE(Pat3->match(""));
37 Expected<GlobPattern> Pat4 = GlobPattern::create("[abc-fy-z]");
38 EXPECT_TRUE((bool)Pat4);
39 EXPECT_TRUE(Pat4->match("a"));
40 EXPECT_TRUE(Pat4->match("b"));
41 EXPECT_TRUE(Pat4->match("c"));
42 EXPECT_TRUE(Pat4->match("d"));
43 EXPECT_TRUE(Pat4->match("e"));
44 EXPECT_TRUE(Pat4->match("f"));
45 EXPECT_TRUE(Pat4->match("y"));
46 EXPECT_TRUE(Pat4->match("z"));
47 EXPECT_FALSE(Pat4->match("g"));
48 EXPECT_FALSE(Pat4->match(""));
50 Expected<GlobPattern> Pat5 = GlobPattern::create("[^abc-fy-z]");
51 EXPECT_TRUE((bool)Pat5);
52 EXPECT_TRUE(Pat5->match("g"));
53 EXPECT_FALSE(Pat5->match("a"));
54 EXPECT_FALSE(Pat5->match("b"));
55 EXPECT_FALSE(Pat5->match("c"));
56 EXPECT_FALSE(Pat5->match("d"));
57 EXPECT_FALSE(Pat5->match("e"));
58 EXPECT_FALSE(Pat5->match("f"));
59 EXPECT_FALSE(Pat5->match("y"));
60 EXPECT_FALSE(Pat5->match("z"));
61 EXPECT_FALSE(Pat5->match(""));
64 TEST_F(GlobPatternTest, Invalid) {
65 Expected<GlobPattern> Pat1 = GlobPattern::create("[");
66 EXPECT_FALSE((bool)Pat1);
67 handleAllErrors(Pat1.takeError(), [&](ErrorInfoBase &EIB) {});
70 TEST_F(GlobPatternTest, ExtSym) {
71 Expected<GlobPattern> Pat1 = GlobPattern::create("a*\xFF");
72 EXPECT_TRUE((bool)Pat1);
73 EXPECT_TRUE(Pat1->match("axxx\xFF"));
74 Expected<GlobPattern> Pat2 = GlobPattern::create("[\xFF-\xFF]");
75 EXPECT_TRUE((bool)Pat2);
76 EXPECT_TRUE(Pat2->match("\xFF"));