1 //===- llvm/unittest/Support/GlobPatternTest.cpp --------------------------===//
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 "llvm/Support/GlobPattern.h"
11 #include "gtest/gtest.h"
16 class GlobPatternTest
: public ::testing::Test
{};
18 TEST_F(GlobPatternTest
, Basics
) {
19 Expected
<GlobPattern
> Pat1
= GlobPattern::create("");
20 EXPECT_TRUE((bool)Pat1
);
21 EXPECT_TRUE(Pat1
->match(""));
22 EXPECT_FALSE(Pat1
->match("a"));
24 Expected
<GlobPattern
> Pat2
= GlobPattern::create("ab*c*def");
25 EXPECT_TRUE((bool)Pat2
);
26 EXPECT_TRUE(Pat2
->match("abcdef"));
27 EXPECT_TRUE(Pat2
->match("abxcxdef"));
28 EXPECT_FALSE(Pat2
->match(""));
29 EXPECT_FALSE(Pat2
->match("xabcdef"));
30 EXPECT_FALSE(Pat2
->match("abcdefx"));
32 Expected
<GlobPattern
> Pat3
= GlobPattern::create("a??c");
33 EXPECT_TRUE((bool)Pat3
);
34 EXPECT_TRUE(Pat3
->match("axxc"));
35 EXPECT_FALSE(Pat3
->match("axxx"));
36 EXPECT_FALSE(Pat3
->match(""));
38 Expected
<GlobPattern
> Pat4
= GlobPattern::create("[abc-fy-z]");
39 EXPECT_TRUE((bool)Pat4
);
40 EXPECT_TRUE(Pat4
->match("a"));
41 EXPECT_TRUE(Pat4
->match("b"));
42 EXPECT_TRUE(Pat4
->match("c"));
43 EXPECT_TRUE(Pat4
->match("d"));
44 EXPECT_TRUE(Pat4
->match("e"));
45 EXPECT_TRUE(Pat4
->match("f"));
46 EXPECT_TRUE(Pat4
->match("y"));
47 EXPECT_TRUE(Pat4
->match("z"));
48 EXPECT_FALSE(Pat4
->match("g"));
49 EXPECT_FALSE(Pat4
->match(""));
51 Expected
<GlobPattern
> Pat5
= GlobPattern::create("[^abc-fy-z]");
52 EXPECT_TRUE((bool)Pat5
);
53 EXPECT_TRUE(Pat5
->match("g"));
54 EXPECT_FALSE(Pat5
->match("a"));
55 EXPECT_FALSE(Pat5
->match("b"));
56 EXPECT_FALSE(Pat5
->match("c"));
57 EXPECT_FALSE(Pat5
->match("d"));
58 EXPECT_FALSE(Pat5
->match("e"));
59 EXPECT_FALSE(Pat5
->match("f"));
60 EXPECT_FALSE(Pat5
->match("y"));
61 EXPECT_FALSE(Pat5
->match("z"));
62 EXPECT_FALSE(Pat5
->match(""));
65 TEST_F(GlobPatternTest
, Invalid
) {
66 Expected
<GlobPattern
> Pat1
= GlobPattern::create("[");
67 EXPECT_FALSE((bool)Pat1
);
68 handleAllErrors(Pat1
.takeError(), [&](ErrorInfoBase
&EIB
) {});
71 TEST_F(GlobPatternTest
, ExtSym
) {
72 Expected
<GlobPattern
> Pat1
= GlobPattern::create("a*\xFF");
73 EXPECT_TRUE((bool)Pat1
);
74 EXPECT_TRUE(Pat1
->match("axxx\xFF"));
75 Expected
<GlobPattern
> Pat2
= GlobPattern::create("[\xFF-\xFF]");
76 EXPECT_TRUE((bool)Pat2
);
77 EXPECT_TRUE(Pat2
->match("\xFF"));