blob: 0686390565a57cf0cc46235356998e9b1a0a6125 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/slobrok/sbmirror.h>
class MatchTester : public slobrok::api::IMirrorAPI
{
SpecList lookup(vespalib::stringref ) const override {
return SpecList();
}
uint32_t updates() const override { return 0; }
bool ready() const override { return true; }
const std::string name;
void testMatch(const char *n, const char *p, bool expected)
{
TEST_STATE(n);
TEST_STATE(p);
EXPECT_EQUAL(expected, match(n, p));
}
public:
MatchTester(const std::string &n) : name(n) {}
void mustMatch(const std::string &pattern) {
testMatch(name.c_str(), pattern.c_str(), true);
}
void mustNotMatch(const std::string &pattern) {
testMatch(name.c_str(), pattern.c_str(), false);
}
};
TEST("require that pattern matches same string") {
std::string pattern = "foo/bar*zot/qux?foo**bar*/*nop*";
MatchTester name(pattern);
name.mustMatch(pattern);
}
TEST("require that star is prefix match") {
MatchTester name("foo/bar.foo/qux.bar/bar123/nop000");
name.mustMatch("foo/bar.*/qux.*/bar*/nop*");
}
TEST("require that star matches empty string") {
MatchTester name("foo/bar./qux./bar/nop");
name.mustMatch("foo/bar.*/qux.*/bar*/nop*");
}
TEST("require that extra char before slash does not match") {
MatchTester name("foo1/bar");
name.mustNotMatch("foo/*");
}
TEST("require that star does not match multiple levels") {
MatchTester name1("foo/bar/qux");
MatchTester name2("foo/bar/bar/qux");
name1.mustMatch("foo/*/qux");
name2.mustNotMatch("foo/*/qux");
}
TEST("require that double star matches multiple levels") {
MatchTester name("foo/bar.foo/qux.bar/bar123/nop000");
name.mustMatch("**");
name.mustMatch("f**");
name.mustMatch("foo**");
name.mustMatch("foo/**");
name.mustMatch("foo*/**");
}
TEST("require that double star matches nothing") {
MatchTester name("A");
name.mustMatch("A**");
}
TEST("require that double star eats rest of name") {
MatchTester name("foo/bar/baz/suffix");
name.mustNotMatch("foo/**/suffix");
}
TEST_MAIN() { TEST_RUN_ALL(); }
|