forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSSTests.swift
139 lines (118 loc) · 4.02 KB
/
RSSTests.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
/**
* Plot
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Plot
final class RSSTests: XCTestCase {
func testEmptyFeed() {
let feed = RSS()
assertEqualRSSFeedContent(feed, "")
}
func testFeedTitle() {
let feed = RSS(.title("MyPodcast"))
assertEqualRSSFeedContent(feed, "<title>MyPodcast</title>")
}
func testFeedDescription() {
let feed = RSS(.description("Description"))
assertEqualRSSFeedContent(feed, "<description>Description</description>")
}
func testFeedDescriptionWithHTMLContent() {
let feed = RSS(
.description(
.p(
.text("Description with "),
.em("emphasis"),
.text(".")
)
)
)
assertEqualRSSFeedContent(feed, "<description><![CDATA[<p>Description with <em>emphasis</em>.</p>]]></description>")
}
func testFeedURL() {
let feed = RSS(.link("url.com"))
assertEqualRSSFeedContent(feed, "<link>url.com</link>")
}
func testFeedAtomLink() {
let feed = RSS(.atomLink("url.com"))
assertEqualRSSFeedContent(feed, """
<atom:link href="url.com" rel="self" type="application/rss+xml"/>
""")
}
func testFeedLanguage() {
let feed = RSS(.language(.usEnglish))
assertEqualRSSFeedContent(feed, "<language>en-us</language>")
}
func testFeedTTL() {
let feed = RSS(.ttl(200))
assertEqualRSSFeedContent(feed, "<ttl>200</ttl>")
}
func testFeedPublicationDate() throws {
let stubs = try Date.makeStubs(withFormattingStyle: .rss)
let feed = RSS(.pubDate(stubs.date, timeZone: stubs.timeZone))
assertEqualRSSFeedContent(feed, "<pubDate>\(stubs.expectedString)</pubDate>")
}
func testFeedLastBuildDate() throws {
let stubs = try Date.makeStubs(withFormattingStyle: .rss)
let feed = RSS(.lastBuildDate(stubs.date, timeZone: stubs.timeZone))
assertEqualRSSFeedContent(feed, "<lastBuildDate>\(stubs.expectedString)</lastBuildDate>")
}
func testItemGUID() {
let feed = RSS(
.item(.guid("123")),
.item(.guid("url.com", .isPermaLink(true))),
.item(.guid("123", .isPermaLink(false)))
)
assertEqualRSSFeedContent(feed, """
<item><guid>123</guid></item>\
<item><guid isPermaLink="true">url.com</guid></item>\
<item><guid isPermaLink="false">123</guid></item>
""")
}
func testItemTitle() {
let feed = RSS(.item(.title("Title")))
assertEqualRSSFeedContent(feed, "<item><title>Title</title></item>")
}
func testItemDescription() {
let feed = RSS(.item(.description("Description")))
assertEqualRSSFeedContent(feed, """
<item><description>Description</description></item>
""")
}
func testItemURL() {
let feed = RSS(.item(.link("url.com")))
assertEqualRSSFeedContent(feed, "<item><link>url.com</link></item>")
}
func testItemPublicationDate() throws {
let stubs = try Date.makeStubs(withFormattingStyle: .rss)
let feed = RSS(.item(.pubDate(stubs.date, timeZone: stubs.timeZone)))
assertEqualRSSFeedContent(feed, """
<item><pubDate>\(stubs.expectedString)</pubDate></item>
""")
}
func testItemHTMLStringContent() {
let feed = RSS(.item(.content(
"<p>Hello</p><p>World & Everyone!</p>"
)))
assertEqualRSSFeedContent(feed, """
<item>\
<content:encoded>\
<![CDATA[<p>Hello</p><p>World & Everyone!</p>]]>\
</content:encoded>\
</item>
""")
}
func testItemHTMLDSLContent() {
let feed = RSS(.item(
.content(.h1("Title"))
))
assertEqualRSSFeedContent(feed, """
<item>\
<content:encoded>\
<![CDATA[<h1>Title</h1>]]>\
</content:encoded>\
</item>
""")
}
}