-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWildcardPatternTest.m
106 lines (83 loc) · 3.4 KB
/
WildcardPatternTest.m
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#import "WildcardPatternTest.h"
@implementation WildcardPatternTest
- (void) testString
{
WildcardPattern* pat;
pat = [[WildcardPattern alloc] initWithString: @"foo"];
STAssertTrue([[pat string] isEqualTo: @"foo"], @"initializer");
[pat setString: @"bar"];
STAssertTrue([[pat string] isEqualTo: @"bar"], @"setter");
[pat release];
}
- (void) testPlainMatch
{
WildcardPattern* pat;
pat = [[WildcardPattern alloc] initWithString: @"abc"];
STAssertTrue([pat isMatch: @"abc"],
@"equal.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"abc"];
STAssertFalse([pat isMatch: @"abcdef"],
@"string is longer than pattern.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"abcdef"];
STAssertFalse([pat isMatch: @"abc"],
@"pattern is longer than string.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"abc"];
STAssertFalse([pat isMatch: @"def"],
@"not equal.");
[pat release];
}
- (void) testWildcardMatch
{
WildcardPattern* pat;
pat = [[WildcardPattern alloc] initWithString: @"*cdef"];
STAssertTrue([pat isMatch: @"abcdef"],
@"'*' at begin.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"*cd"];
STAssertFalse([pat isMatch: @"abcdef"],
@"*' at begin, but pattern is too short.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"*cdef"];
STAssertFalse([pat isMatch: @"abcd"],
@"*' at begin, but pattern is too long.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"abcd*"];
STAssertTrue([pat isMatch: @"abcdef"],
@"'*' at end.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"abcd*"];
STAssertTrue([pat isMatch: @"abcd"],
@"'*' at end, '*' match '\\0'.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"ab*ef"];
STAssertTrue([pat isMatch: @"abcdef"],
@"'*' at middle.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"ab*ef"];
STAssertFalse([pat isMatch: @"abcd"],
@"'*' at middle, but pattern is too long.");
[pat release];
pat = [[WildcardPattern alloc] initWithString: @"ab*ef"];
STAssertFalse([pat isMatch: @"abcdefgh"],
@"'*' at middle, but pattern is too short.");
[pat release];
STAssertFalse([[WildcardPattern patternWithString: @"a.c"] isMatch: @"abc"],
@"'.' is not meta char.");
pat = [WildcardPattern patternWithString: @"google.tld"];
STAssertTrue([pat isMatch: @"google.com"], @"'google.tld' match '.com'.");
STAssertTrue([pat isMatch: @"google.co.jp"],
@"'google.tld' match '.co.jp'. it's not TLD...");
pat = [WildcardPattern patternWithString: @"example.tld"];
STAssertTrue([pat isMatch: @"example.jp"],
@"'.tld' match '.jp'.");
STAssertTrue([pat isMatch: @"example.tokyo.jp"],
@"'.tld' match '.tokyo.jp'.");
STAssertTrue([pat isMatch: @"example.nottokyo.jp"],
@"'.tld' match '.nottokyo.jp'.");
STAssertFalse([pat isMatch: @"example.not-tokyo.jp"],
@"'.tld' don't match '.not-tokyo.jp'.");
}
@end