forked from Cocoanetics/DTCoreText
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSStringHTMLTest.m
More file actions
135 lines (108 loc) · 4.24 KB
/
Copy pathNSStringHTMLTest.m
File metadata and controls
135 lines (108 loc) · 4.24 KB
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
//
// NSStringHTMLTest.m
// DTCoreText
//
// Created by Claus Broch on 11/01/11.
// Copyright 2011 Drobnik.com. All rights reserved.
//
#import "NSStringHTMLTest.h"
@implementation NSStringHTMLTest
- (void)testEmojiEncodingAndDecoding
{
NSString *string = @"😄";
// check encoding
NSString *encoded = [string stringByAddingHTMLEntities];
XCTAssertEqualObjects(encoded, @"😄", @"Smiley is not properly encoded");
// check reverse
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, string, @"Smiley is not properly round trip decoded");
}
- (void)testHexDecoding
{
NSString *encoded = @"😄";
NSString *expected = @"😄";
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testKnownEntityDecoding
{
NSString *encoded = @"<>";
NSString *expected = @"<>";
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testUnclosedDecoding
{
NSString *encoded = @"😄test";
NSString *expected = encoded;
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testUnclosedHexDecoding
{
NSString *encoded = @"😄test";
NSString *expected = encoded;
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testUnclosedKnownEntityDecoding
{
NSString *encoded = @"<test";
NSString *expected = encoded;
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testInvalidDecoding
{
NSString *encoded = @"&#hello;";
NSString *expected = encoded;
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testInvalidHexDecoding
{
NSString *encoded = @"&#xsup;";
NSString *expected = encoded;
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testUnknownEntityDecoding
{
NSString *encoded = @"&unknowncode;";
NSString *expected = encoded;
NSString *decoded = [encoded stringByReplacingHTMLEntities];
XCTAssertEqualObjects(decoded, expected, @"String is not properly decoded");
}
- (void)testStringByAddingAppleConvertedSpace
{
NSMutableString *convertedStringExpected = [NSMutableString string];
// One space
NSString *string = @"1 1";
[convertedStringExpected setString:@"1 1"];
NSString *convertedString = [string stringByAddingAppleConvertedSpace];
XCTAssertTrue([convertedString isEqualToString:convertedStringExpected], @"Spaces do not get converted properly");
// Two spaces
string = @"2 2";
[convertedStringExpected setString:@"2 <span class=\"Apple-converted-space\">"];
[convertedStringExpected appendString:UNICODE_NON_BREAKING_SPACE];
[convertedStringExpected appendString:@"</span>2"];
convertedString = [string stringByAddingAppleConvertedSpace];
XCTAssertTrue([convertedString isEqualToString:convertedStringExpected], @"Spaces do not get converted properly");
// Three spaces
string = @"3 3";
[convertedStringExpected setString:@"3 <span class=\"Apple-converted-space\">"];
[convertedStringExpected appendString:UNICODE_NON_BREAKING_SPACE];
[convertedStringExpected appendString:@" </span>3"];
convertedString = [string stringByAddingAppleConvertedSpace];
XCTAssertTrue([convertedString isEqualToString:convertedStringExpected], @"Spaces do not get converted properly");
// Four spaces
string = @"4 4";
[convertedStringExpected setString:@"4 <span class=\"Apple-converted-space\">"];
[convertedStringExpected appendString:UNICODE_NON_BREAKING_SPACE];
[convertedStringExpected appendString:@" "];
[convertedStringExpected appendString:UNICODE_NON_BREAKING_SPACE];
[convertedStringExpected appendString:@"</span>4"];
convertedString = [string stringByAddingAppleConvertedSpace];
XCTAssertTrue([convertedString isEqualToString:convertedStringExpected], @"Spaces do not get converted properly");
}
@end