/
TextFormattingTests.swift
170 lines (142 loc) · 6.48 KB
/
TextFormattingTests.swift
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* Ink
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Ink
final class TextFormattingTests: XCTestCase {
func testParagraph() {
let html = MarkdownParser().html(from: "Hello, world!")
XCTAssertEqual(html, "<p>Hello, world!</p>")
}
func testItalicText() {
let html = MarkdownParser().html(from: "Hello, *world*!")
XCTAssertEqual(html, "<p>Hello, <em>world</em>!</p>")
}
func testBoldText() {
let html = MarkdownParser().html(from: "Hello, **world**!")
XCTAssertEqual(html, "<p>Hello, <strong>world</strong>!</p>")
}
func testItalicBoldText() {
let html = MarkdownParser().html(from: "Hello, ***world***!")
XCTAssertEqual(html, "<p>Hello, <strong><em>world</em></strong>!</p>")
}
func testItalicBoldTextWithSeparateStartMarkers() {
let html = MarkdownParser().html(from: "**Hello, *world***!")
XCTAssertEqual(html, "<p><strong>Hello, <em>world</em></strong>!</p>")
}
func testItalicTextWithinBoldText() {
let html = MarkdownParser().html(from: "**Hello, *world*!**")
XCTAssertEqual(html, "<p><strong>Hello, <em>world</em>!</strong></p>")
}
func testBoldTextWithinItalicText() {
let html = MarkdownParser().html(from: "*Hello, **world**!*")
XCTAssertEqual(html, "<p><em>Hello, <strong>world</strong>!</em></p>")
}
func testItalicTextWithExtraLeadingMarkers() {
let html = MarkdownParser().html(from: "**Hello*")
XCTAssertEqual(html, "<p>*<em>Hello</em></p>")
}
func testBoldTextWithExtraLeadingMarkers() {
let html = MarkdownParser().html(from: "***Hello**")
XCTAssertEqual(html, "<p><strong>*Hello</strong></p>")
}
func testItalicTextWithExtraTrailingMarkers() {
let html = MarkdownParser().html(from: "*Hello**")
XCTAssertEqual(html, "<p><em>Hello</em>*</p>")
}
func testBoldTextWithExtraTrailingMarkers() {
let html = MarkdownParser().html(from: "**Hello***")
XCTAssertEqual(html, "<p><strong>Hello</strong>*</p>")
}
func testItalicBoldTextWithExtraTrailingMarkers() {
let html = MarkdownParser().html(from: "**Hello, *world*****!")
XCTAssertEqual(html, "<p><strong>Hello, <em>world</em></strong>**!</p>")
}
func testUnterminatedItalicMarker() {
let html = MarkdownParser().html(from: "*Hello")
XCTAssertEqual(html, "<p>*Hello</p>")
}
func testUnterminatedBoldMarker() {
let html = MarkdownParser().html(from: "**Hello")
XCTAssertEqual(html, "<p>**Hello</p>")
}
func testUnterminatedItalicBoldMarker() {
let html = MarkdownParser().html(from: "***Hello")
XCTAssertEqual(html, "<p>***Hello</p>")
}
func testUnterminatedItalicMarkerWithinBoldText() {
let html = MarkdownParser().html(from: "**Hello, *world!**")
XCTAssertEqual(html, "<p><strong>Hello, *world!</strong></p>")
}
func testUnterminatedBoldMarkerWithinItalicText() {
let html = MarkdownParser().html(from: "*Hello, **world!*")
XCTAssertEqual(html, "<p><em>Hello, **world!</em></p>")
}
func testStrikethroughText() {
let html = MarkdownParser().html(from: "Hello, ~~world!~~")
XCTAssertEqual(html, "<p>Hello, <s>world!</s></p>")
}
func testSingleTildeWithinStrikethroughText() {
let html = MarkdownParser().html(from: "Hello, ~~wor~ld!~~")
XCTAssertEqual(html, "<p>Hello, <s>wor~ld!</s></p>")
}
func testUnterminatedStrikethroughMarker() {
let html = MarkdownParser().html(from: "~~Hello")
XCTAssertEqual(html, "<p>~~Hello</p>")
}
func testEncodingSpecialCharacters() {
let html = MarkdownParser().html(from: "Hello < World & >")
XCTAssertEqual(html, "<p>Hello < World & ></p>")
}
func testSingleLineBlockquote() {
let html = MarkdownParser().html(from: "> Hello, world!")
XCTAssertEqual(html, "<blockquote><p>Hello, world!</p></blockquote>")
}
func testMultiLineBlockquote() {
let html = MarkdownParser().html(from: """
> One
> Two
> Three
""")
XCTAssertEqual(html, "<blockquote><p>One Two Three</p></blockquote>")
}
func testEscapingSymbolsWithBackslash() {
let html = MarkdownParser().html(from: """
\\# Not a title
\\*Not italic\\*
""")
XCTAssertEqual(html, "<p># Not a title *Not italic*</p>")
}
}
extension TextFormattingTests {
static var allTests: [(String, TestClosure<TextFormattingTests>)] {
return [
("testParagraph", testParagraph),
("testItalicText", testItalicText),
("testBoldText", testBoldText),
("testItalicBoldText", testItalicBoldText),
("testItalicBoldTextWithSeparateStartMarkers", testItalicBoldTextWithSeparateStartMarkers),
("testItalicTextWithinBoldText", testItalicTextWithinBoldText),
("testBoldTextWithinItalicText", testBoldTextWithinItalicText),
("testItalicTextWithExtraLeadingMarkers", testItalicTextWithExtraLeadingMarkers),
("testBoldTextWithExtraLeadingMarkers", testBoldTextWithExtraLeadingMarkers),
("testItalicTextWithExtraTrailingMarkers", testItalicTextWithExtraTrailingMarkers),
("testBoldTextWithExtraTrailingMarkers", testBoldTextWithExtraTrailingMarkers),
("testItalicBoldTextWithExtraTrailingMarkers", testItalicBoldTextWithExtraTrailingMarkers),
("testUnterminatedItalicMarker", testUnterminatedItalicMarker),
("testUnterminatedBoldMarker", testUnterminatedBoldMarker),
("testUnterminatedItalicBoldMarker", testUnterminatedItalicBoldMarker),
("testUnterminatedItalicMarkerWithinBoldText", testUnterminatedItalicMarkerWithinBoldText),
("testUnterminatedBoldMarkerWithinItalicText", testUnterminatedBoldMarkerWithinItalicText),
("testStrikethroughText", testStrikethroughText),
("testSingleTildeWithinStrikethroughText", testSingleTildeWithinStrikethroughText),
("testUnterminatedStrikethroughMarker", testUnterminatedStrikethroughMarker),
("testEncodingSpecialCharacters", testEncodingSpecialCharacters),
("testSingleLineBlockquote", testSingleLineBlockquote),
("testMultiLineBlockquote", testMultiLineBlockquote),
("testEscapingSymbolsWithBackslash", testEscapingSymbolsWithBackslash)
]
}
}