-
Notifications
You must be signed in to change notification settings - Fork 8
/
TestPlaceholderExpansion.m
149 lines (122 loc) · 7.11 KB
/
TestPlaceholderExpansion.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*******************************************************************************
Copyright (c) 2011 Jordy Rose
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior authorization.
*******************************************************************************/
#import <SenTestingKit/SenTestingKit.h>
#import "NSString+PrototypeExpansion.h"
@interface TestPrototypeExpansion : SenTestCase
@end
static NSString * const testingURL = @"mailto:[email protected]?one=11&two=22";
@implementation TestPrototypeExpansion
- (void)testNoPlaceholders
{
NSString *str = @"this is a string with %no placeholders%";
STAssertEqualObjects(str, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testEndsWithOpenBracket
{
NSString *str = @"this ends with a [";
STAssertEqualObjects(str, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testIncompletePlaceholder
{
NSString *str = @"this ends with an incomplete [placeholder";
STAssertEqualObjects(str, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testValidPlaceholders
{
NSString *str = @"this has a [to] placeholder";
NSString *expected = @"this has a [email protected] placeholder";
STAssertEqualObjects(expected, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
str = @"this has a [two] placeholder";
expected = @"this has a 22 placeholder";
STAssertEqualObjects(expected, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
str = @"this ends with [one]";
expected = @"this ends with 11";
STAssertEqualObjects(expected, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
str = @"[to] starts this one";
expected = @"[email protected] starts this one";
STAssertEqualObjects(expected, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testInvalidPlaceholders
{
NSString *str = @"this has a [random] placeholder";
NSString *expected = @"this has a placeholder";
STAssertEqualObjects(expected, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testEmpty
{
NSString *str = @"";
STAssertEqualObjects(str, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testEmptyPlaceholder
{
NSString *str = @"this has an empty [] placeholder";
STAssertEqualObjects(str, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testMultiplePlaceholders
{
NSString *str = @"this has [one], [two], [three] placeholders";
NSString *expected = @"this has 11, 22, placeholders";
STAssertEqualObjects(expected, [str replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"");
}
- (void)testBasicModifiers
{
NSString *emailWithPunctuation = @"mailto:0'^0";
NSString *template = @"[to]: [%to] [#to] [%#to]";
NSString *expected = @"0'^0: 0'%5E0 4 6";
NSString *expectedQuotes = @"0%27^0: 0%27%5E0 6 8";
NSString *actual = [template replaceWebmailerPlaceholdersUsingMailtoURLString:emailWithPunctuation alwaysEscapeQuotes:NO];
NSString *actualQuotes = [template replaceWebmailerPlaceholdersUsingMailtoURLString:emailWithPunctuation alwaysEscapeQuotes:YES];
STAssertEqualObjects(expected, actual, @"");
STAssertEqualObjects(expectedQuotes, actualQuotes, @"");
}
- (void)testQuestionMark
{
NSString *template = @"?[?]";
NSString *templateLeading = @"to?[?]";
NSString *templateLeadingPlaceholder = @"[to]?[?]";
NSString *templateTrailing = @"?[?]&abc=def";
NSString *templateLeadingTrailing = @"to?[?]&abc=def";
NSString *templateLeadingPlaceholderTrailing = @"[to]?[?]&abc=def";
STAssertEqualObjects([template replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"?one=11&two=22", @"");
STAssertEqualObjects([templateLeading replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"to?one=11&two=22", @"");
STAssertEqualObjects([templateLeadingPlaceholder replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"[email protected]?one=11&two=22", @"");
STAssertEqualObjects([templateTrailing replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"?one=11&two=22&abc=def", @"");
STAssertEqualObjects([templateLeadingTrailing replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"to?one=11&two=22&abc=def", @"");
STAssertEqualObjects([templateLeadingPlaceholderTrailing replaceWebmailerPlaceholdersUsingMailtoURLString:testingURL alwaysEscapeQuotes:NO], @"[email protected]?one=11&two=22&abc=def", @"");
}
- (void)testNoExtraQuestionMark
{
NSString *template = @"?[?]";
NSString *templateLeading = @"to?[?]";
NSString *templateLeadingPlaceholder = @"[to]?[?]";
NSString *templateTrailing = @"?[?]&abc=def";
NSString *templateLeadingTrailing = @"to?[?]&abc=def";
NSString *templateLeadingPlaceholderTrailing = @"[to]?[?]&abc=def";
NSString *simpleURL = @"mailto:[email protected]";
STAssertEqualObjects([template replaceWebmailerPlaceholdersUsingMailtoURLString:simpleURL alwaysEscapeQuotes:NO], @"", @"");
STAssertEqualObjects([templateLeading replaceWebmailerPlaceholdersUsingMailtoURLString:simpleURL alwaysEscapeQuotes:NO], @"to?", @"");
STAssertEqualObjects([templateLeadingPlaceholder replaceWebmailerPlaceholdersUsingMailtoURLString:simpleURL alwaysEscapeQuotes:NO], @"[email protected]", @"");
STAssertEqualObjects([templateTrailing replaceWebmailerPlaceholdersUsingMailtoURLString:simpleURL alwaysEscapeQuotes:NO], @"&abc=def", @"");
STAssertEqualObjects([templateLeadingTrailing replaceWebmailerPlaceholdersUsingMailtoURLString:simpleURL alwaysEscapeQuotes:NO], @"to?&abc=def", @"");
STAssertEqualObjects([templateLeadingPlaceholderTrailing replaceWebmailerPlaceholdersUsingMailtoURLString:simpleURL alwaysEscapeQuotes:NO], @"[email protected]&abc=def", @"");
}
@end