Skip to content
Newer
Older
100644 128 lines (90 sloc) 6.61 KB
ed20d90 @soffes Added tests for categories
soffes authored Apr 14, 2011
1 //
2 // StringCategoryTest.m
3 // SSToolkit
4 //
5 // Created by Sam Soffes on 4/14/11.
6 // Copyright 2011 Sam Soffes. All rights reserved.
7 //
8
9 #import <SSToolkit/NSString+SSToolkitAdditions.h>
10
11 @interface StringCategoryTest : GHTestCase
12 @end
13
14 @implementation StringCategoryTest
15
16 // To test:
17 //- (NSString *)URLEncodedString;
18 //- (NSString *)URLEncodedParameterString;
19 //- (NSString *)URLDecodedString;
20
3829132 @soffes Added more array, string, and url tests
soffes authored Apr 14, 2011
21 - (void)testContainsString {
22 NSString *string = @"alexanderthegreat";
23
24 GHAssertTrue([string containsString:@"alex"], nil);
25 GHAssertFalse([string containsString:@"awesome"], nil);
26 }
27
28
29 - (void)testMD5Sum {
30 GHAssertEqualObjects([@"sam" MD5Sum], @"332532dcfaa1cbf61e2a266bd723612c", nil);
31
32 NSString *lorem = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
33 GHAssertEqualObjects([lorem MD5Sum], @"fa5c89f3c88b81bfd5e821b0316569af", nil);
34 }
35
36
37 - (void)testSHA1Sum {
38 GHAssertEqualObjects([@"sam" SHA1Sum], @"f16bed56189e249fe4ca8ed10a1ecae60e8ceac0", nil);
39
40 NSString *lorem = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
41 GHAssertEqualObjects([lorem SHA1Sum], @"19afa2a4a37462c7b940a6c4c61363d49c3a35f4", nil);
42 }
43
44
45 - (void)testCompareToVersionString {
46 GHAssertEquals([@"1.0.0" compareToVersionString:@"0.0.1"], NSOrderedDescending, nil);
47 GHAssertEquals([@"3.2" compareToVersionString:@"4.2"], NSOrderedAscending, nil);
48 GHAssertEquals([@"3.2.1" compareToVersionString:@"4.2.1"], NSOrderedAscending, nil);
7cd437c @soffes Started on NSString category documentation #24. Added SHA1Sum to NSDa…
soffes authored Jul 10, 2011
49
50 GHAssertEquals([@"10.4" compareToVersionString:@"10.3"], NSOrderedDescending, nil);
51 GHAssertEquals([@"10.5" compareToVersionString:@"10.5.0"], NSOrderedSame, nil);
52 GHAssertEquals([@"10.4 Build 8L127" compareToVersionString:@"10.4 Build 8P135"], NSOrderedAscending, nil);
3829132 @soffes Added more array, string, and url tests
soffes authored Apr 15, 2011
53 }
54
1a4a389 @soffes More data and string tests
soffes authored Apr 14, 2011
55
56 - (void)testBase64EncodedString {
2ad922a @soffes Added Base64 decoding. Fixes #2
soffes authored Jul 10, 2011
57 NSString *unencodedString = @"sam";
58 NSString *encodedString = @"c2Ft";
59 GHAssertEqualObjects(encodedString, [unencodedString base64EncodedString], nil);
60 GHAssertEqualObjects(unencodedString, [NSString stringWithBase64String:encodedString], nil);
1a4a389 @soffes More data and string tests
soffes authored Apr 15, 2011
61
2ad922a @soffes Added Base64 decoding. Fixes #2
soffes authored Jul 10, 2011
62 unencodedString = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
63 encodedString = @"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2ljaW5nIGVsaXQsIHNlZCBkbyBlaXVzbW9kIHRlbXBvciBpbmNpZGlkdW50IHV0IGxhYm9yZSBldCBkb2xvcmUgbWFnbmEgYWxpcXVhLiBVdCBlbmltIGFkIG1pbmltIHZlbmlhbSwgcXVpcyBub3N0cnVkIGV4ZXJjaXRhdGlvbiB1bGxhbWNvIGxhYm9yaXMgbmlzaSB1dCBhbGlxdWlwIGV4IGVhIGNvbW1vZG8gY29uc2VxdWF0LiBEdWlzIGF1dGUgaXJ1cmUgZG9sb3IgaW4gcmVwcmVoZW5kZXJpdCBpbiB2b2x1cHRhdGUgdmVsaXQgZXNzZSBjaWxsdW0gZG9sb3JlIGV1IGZ1Z2lhdCBudWxsYSBwYXJpYXR1ci4gRXhjZXB0ZXVyIHNpbnQgb2NjYWVjYXQgY3VwaWRhdGF0IG5vbiBwcm9pZGVudCwgc3VudCBpbiBjdWxwYSBxdWkgb2ZmaWNpYSBkZXNlcnVudCBtb2xsaXQgYW5pbSBpZCBlc3QgbGFib3J1bS4=";
64 GHAssertEqualObjects(encodedString, [unencodedString base64EncodedString], nil);
65 GHAssertEqualObjects(unencodedString, [NSString stringWithBase64String:encodedString], nil);
66
67 unencodedString = @"http://www.cocoadev.com/index.pl?BaseSixtyFour";
68 encodedString = @"aHR0cDovL3d3dy5jb2NvYWRldi5jb20vaW5kZXgucGw/QmFzZVNpeHR5Rm91cg==";
69 GHAssertEqualObjects(encodedString, [unencodedString base64EncodedString], nil);
70 GHAssertEqualObjects(unencodedString, [NSString stringWithBase64String:encodedString], nil);
1a4a389 @soffes More data and string tests
soffes authored Apr 15, 2011
71 }
72
73
c7d0611 @soffes Document and test `escapeHTML` and `unescapeHTML` in NSString category
soffes authored Jul 11, 2011
74 - (void)testEscapingAndUnescapingHTML {
75 NSString *html = @"<a href=\"http://example.com/?ruby%3F=yes&amp;var=T\">example</a>";
76 NSString *escapedHtml = @"&lt;a href=&quot;http://example.com/?ruby%3F=yes&amp;amp;var=T&quot;&gt;example&lt;/a&gt;";
77
78 GHAssertEqualObjects([html escapeHTML], escapedHtml, nil);
79 GHAssertEqualObjects([escapedHtml unescapeHTML], html, nil);
80 }
81
82
1a4a389 @soffes More data and string tests
soffes authored Apr 15, 2011
83 - (void)testStringByEscapingForURLQuery {
84 GHAssertEqualObjects([@"I want a 27-inch iMac!" stringByEscapingForURLQuery], @"I+want+a+27-inch+iMac%21", nil);
65c9868 @soffes Added another string category test
soffes authored Jul 11, 2011
85 GHAssertEqualObjects([@"myemail+category@gmail.com" stringByEscapingForURLQuery], @"myemail%2Bcategory%40gmail.com", nil);
1a4a389 @soffes More data and string tests
soffes authored Apr 15, 2011
86 }
87
88
89 - (void)testStringByUnescapingFromURLQuery {
90 GHAssertEqualObjects([@"I+want+a+27-inch+iMac%21" stringByUnescapingFromURLQuery], @"I want a 27-inch iMac!", nil);
65c9868 @soffes Added another string category test
soffes authored Jul 11, 2011
91 GHAssertEqualObjects([@"myemail%2Bcategory%40gmail.com" stringByUnescapingFromURLQuery], @"myemail+category@gmail.com", nil);
1a4a389 @soffes More data and string tests
soffes authored Apr 15, 2011
92 }
93
d56b517 @mattdipasquale Added Trimming Methods & tests to NSString category
mattdipasquale authored Apr 17, 2011
94
625e9ac @soffes Add SSManagedOperationQueue and `+[NSString stringWithUUID]`
soffes authored Nov 9, 2011
95 - (void)testUUID {
96 NSString *uuid1 = [NSString stringWithUUID];
97 NSString *uuid2 = [NSString stringWithUUID];
98 GHAssertNotEqualObjects(uuid1, uuid2, nil);
99 }
100
101
d56b517 @mattdipasquale Added Trimming Methods & tests to NSString category
mattdipasquale authored Apr 17, 2011
102 - (void)testStringByTrimmingLeadingCharactersInSet {
103 NSCharacterSet *letterCharSet = [NSCharacterSet letterCharacterSet];
104 GHAssertEqualObjects([@"zip90210zip" stringByTrimmingLeadingCharactersInSet:letterCharSet], @"90210zip", nil);
105 }
106
107
108 - (void)testStringByTrimmingLeadingWhitespaceAndNewlineCharacters {
109 GHAssertEqualObjects([@"" stringByTrimmingLeadingWhitespaceAndNewlineCharacters], @"", nil);
110 GHAssertEqualObjects([@"\n \n " stringByTrimmingLeadingWhitespaceAndNewlineCharacters], @"", nil);
111 GHAssertEqualObjects([@"\n hello \n" stringByTrimmingLeadingWhitespaceAndNewlineCharacters], @"hello \n", nil);
112 }
113
114
115 - (void)testStringByTrimmingTrailingCharactersInSet {
116 NSCharacterSet *letterCharSet = [NSCharacterSet letterCharacterSet];
117 GHAssertEqualObjects([@"zip90210zip" stringByTrimmingTrailingCharactersInSet:letterCharSet], @"zip90210", nil);
118 }
119
120
121 - (void)testStringByTrimmingTrailingWhitespaceAndNewlineCharacters {
122 GHAssertEqualObjects([@"" stringByTrimmingLeadingWhitespaceAndNewlineCharacters], @"", nil);
123 GHAssertEqualObjects([@"\n \n " stringByTrimmingLeadingWhitespaceAndNewlineCharacters], @"", nil);
124 GHAssertEqualObjects([@"\n hello \n" stringByTrimmingTrailingWhitespaceAndNewlineCharacters], @"\n hello", nil);
125 }
126
ed20d90 @soffes Added tests for categories
soffes authored Apr 15, 2011
127 @end
Something went wrong with that request. Please try again.