parser_test.go 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package rss // import "miniflux.app/reader/rss"
  5. import (
  6. "bytes"
  7. "testing"
  8. "time"
  9. )
  10. func TestParseRss2Sample(t *testing.T) {
  11. data := `
  12. <?xml version="1.0"?>
  13. <rss version="2.0">
  14. <channel>
  15. <title>Liftoff News</title>
  16. <link>http://liftoff.msfc.nasa.gov/</link>
  17. <description>Liftoff to Space Exploration.</description>
  18. <language>en-us</language>
  19. <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
  20. <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
  21. <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  22. <generator>Weblog Editor 2.0</generator>
  23. <managingEditor>editor@example.com</managingEditor>
  24. <webMaster>webmaster@example.com</webMaster>
  25. <item>
  26. <title>Star City</title>
  27. <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>
  28. <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's &lt;a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm"&gt;Star City&lt;/a&gt;.</description>
  29. <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
  30. <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid>
  31. </item>
  32. <item>
  33. <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a &lt;a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm"&gt;partial eclipse of the Sun&lt;/a&gt; on Saturday, May 31st.</description>
  34. <pubDate>Fri, 30 May 2003 11:06:42 GMT</pubDate>
  35. <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid>
  36. </item>
  37. <item>
  38. <title>The Engine That Does More</title>
  39. <link>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</link>
  40. <description>Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that.</description>
  41. <pubDate>Tue, 27 May 2003 08:37:32 GMT</pubDate>
  42. <guid>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</guid>
  43. </item>
  44. <item>
  45. <title>Astronauts' Dirty Laundry</title>
  46. <link>http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp</link>
  47. <description>Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.</description>
  48. <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate>
  49. <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid>
  50. </item>
  51. </channel>
  52. </rss>`
  53. feed, err := Parse(bytes.NewBufferString(data))
  54. if err != nil {
  55. t.Fatal(err)
  56. }
  57. if feed.Title != "Liftoff News" {
  58. t.Errorf("Incorrect title, got: %s", feed.Title)
  59. }
  60. if feed.FeedURL != "" {
  61. t.Errorf("Incorrect feed URL, got: %s", feed.FeedURL)
  62. }
  63. if feed.SiteURL != "http://liftoff.msfc.nasa.gov/" {
  64. t.Errorf("Incorrect site URL, got: %s", feed.SiteURL)
  65. }
  66. if len(feed.Entries) != 4 {
  67. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  68. }
  69. expectedDate := time.Date(2003, time.June, 3, 9, 39, 21, 0, time.UTC)
  70. if !feed.Entries[0].Date.Equal(expectedDate) {
  71. t.Errorf("Incorrect entry date, got: %v, want: %v", feed.Entries[0].Date, expectedDate)
  72. }
  73. if feed.Entries[0].Hash != "5b2b4ac2fe1786ddf0fd2da2f1b07f64e691264f41f2db3ea360f31bb6d9152b" {
  74. t.Errorf("Incorrect entry hash, got: %s", feed.Entries[0].Hash)
  75. }
  76. if feed.Entries[0].URL != "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp" {
  77. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  78. }
  79. if feed.Entries[0].Title != "Star City" {
  80. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  81. }
  82. if feed.Entries[0].Content != `How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.` {
  83. t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].Content)
  84. }
  85. }
  86. func TestParseFeedWithoutTitle(t *testing.T) {
  87. data := `<?xml version="1.0" encoding="utf-8"?>
  88. <rss version="2.0">
  89. <channel>
  90. <link>https://example.org/</link>
  91. </channel>
  92. </rss>`
  93. feed, err := Parse(bytes.NewBufferString(data))
  94. if err != nil {
  95. t.Fatal(err)
  96. }
  97. if feed.Title != "https://example.org/" {
  98. t.Errorf("Incorrect feed title, got: %s", feed.Title)
  99. }
  100. }
  101. func TestParseEntryWithoutTitle(t *testing.T) {
  102. data := `<?xml version="1.0" encoding="utf-8"?>
  103. <rss version="2.0">
  104. <channel>
  105. <link>https://example.org/</link>
  106. <item>
  107. <link>https://example.org/item</link>
  108. </item>
  109. </channel>
  110. </rss>`
  111. feed, err := Parse(bytes.NewBufferString(data))
  112. if err != nil {
  113. t.Fatal(err)
  114. }
  115. if feed.Entries[0].Title != "https://example.org/item" {
  116. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  117. }
  118. }
  119. func TestParseEntryWithoutLink(t *testing.T) {
  120. data := `<?xml version="1.0" encoding="utf-8"?>
  121. <rss version="2.0">
  122. <channel>
  123. <link>https://example.org/</link>
  124. <item>
  125. <guid isPermaLink="false">1234</guid>
  126. </item>
  127. </channel>
  128. </rss>`
  129. feed, err := Parse(bytes.NewBufferString(data))
  130. if err != nil {
  131. t.Fatal(err)
  132. }
  133. if feed.Entries[0].URL != "https://example.org/" {
  134. t.Errorf("Incorrect entry link, got: %s", feed.Entries[0].URL)
  135. }
  136. if feed.Entries[0].Hash != "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4" {
  137. t.Errorf("Incorrect entry hash, got: %s", feed.Entries[0].Hash)
  138. }
  139. }
  140. func TestParseEntryWithAtomLink(t *testing.T) {
  141. data := `<?xml version="1.0" encoding="utf-8"?>
  142. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  143. <channel>
  144. <link>https://example.org/</link>
  145. <item>
  146. <title>Test</title>
  147. <atom:link href="https://example.org/item" />
  148. </item>
  149. </channel>
  150. </rss>`
  151. feed, err := Parse(bytes.NewBufferString(data))
  152. if err != nil {
  153. t.Fatal(err)
  154. }
  155. if feed.Entries[0].URL != "https://example.org/item" {
  156. t.Errorf("Incorrect entry link, got: %s", feed.Entries[0].URL)
  157. }
  158. }
  159. func TestParseEntryWithMultipleAtomLinks(t *testing.T) {
  160. data := `<?xml version="1.0" encoding="utf-8"?>
  161. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  162. <channel>
  163. <link>https://example.org/</link>
  164. <item>
  165. <title>Test</title>
  166. <atom:link rel="payment" href="https://example.org/a" />
  167. <atom:link rel="http://foobar.tld" href="https://example.org/b" />
  168. </item>
  169. </channel>
  170. </rss>`
  171. feed, err := Parse(bytes.NewBufferString(data))
  172. if err != nil {
  173. t.Fatal(err)
  174. }
  175. if feed.Entries[0].URL != "https://example.org/b" {
  176. t.Errorf("Incorrect entry link, got: %s", feed.Entries[0].URL)
  177. }
  178. }
  179. func TestParseFeedURLWithAtomLink(t *testing.T) {
  180. data := `<?xml version="1.0" encoding="utf-8"?>
  181. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  182. <channel>
  183. <title>Example</title>
  184. <link>https://example.org/</link>
  185. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  186. </channel>
  187. </rss>`
  188. feed, err := Parse(bytes.NewBufferString(data))
  189. if err != nil {
  190. t.Fatal(err)
  191. }
  192. if feed.FeedURL != "https://example.org/rss" {
  193. t.Errorf("Incorrect feed URL, got: %s", feed.FeedURL)
  194. }
  195. if feed.SiteURL != "https://example.org/" {
  196. t.Errorf("Incorrect site URL, got: %s", feed.SiteURL)
  197. }
  198. }
  199. func TestParseFeedWithWebmaster(t *testing.T) {
  200. data := `<?xml version="1.0" encoding="utf-8"?>
  201. <rss version="2.0">
  202. <channel>
  203. <title>Example</title>
  204. <link>https://example.org/</link>
  205. <webMaster>webmaster@example.com</webMaster>
  206. <item>
  207. <title>Test</title>
  208. <link>https://example.org/item</link>
  209. </item>
  210. </channel>
  211. </rss>`
  212. feed, err := Parse(bytes.NewBufferString(data))
  213. if err != nil {
  214. t.Fatal(err)
  215. }
  216. expected := "webmaster@example.com"
  217. result := feed.Entries[0].Author
  218. if result != expected {
  219. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  220. }
  221. }
  222. func TestParseFeedWithManagingEditor(t *testing.T) {
  223. data := `<?xml version="1.0" encoding="utf-8"?>
  224. <rss version="2.0">
  225. <channel>
  226. <title>Example</title>
  227. <link>https://example.org/</link>
  228. <webMaster>webmaster@example.com</webMaster>
  229. <managingEditor>editor@example.com</managingEditor>
  230. <item>
  231. <title>Test</title>
  232. <link>https://example.org/item</link>
  233. </item>
  234. </channel>
  235. </rss>`
  236. feed, err := Parse(bytes.NewBufferString(data))
  237. if err != nil {
  238. t.Fatal(err)
  239. }
  240. expected := "editor@example.com"
  241. result := feed.Entries[0].Author
  242. if result != expected {
  243. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  244. }
  245. }
  246. func TestParseEntryWithAuthorAndInnerHTML(t *testing.T) {
  247. data := `<?xml version="1.0" encoding="utf-8"?>
  248. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  249. <channel>
  250. <title>Example</title>
  251. <link>https://example.org/</link>
  252. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  253. <item>
  254. <title>Test</title>
  255. <link>https://example.org/item</link>
  256. <author>by <a itemprop="url" class="author" rel="author" href="/author/foobar">Foo Bar</a></author>
  257. </item>
  258. </channel>
  259. </rss>`
  260. feed, err := Parse(bytes.NewBufferString(data))
  261. if err != nil {
  262. t.Fatal(err)
  263. }
  264. expected := "by Foo Bar"
  265. result := feed.Entries[0].Author
  266. if result != expected {
  267. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  268. }
  269. }
  270. func TestParseEntryWithNonStandardAtomAuthor(t *testing.T) {
  271. data := `<?xml version="1.0" encoding="utf-8"?>
  272. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  273. <channel>
  274. <title>Example</title>
  275. <link>https://example.org/</link>
  276. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  277. <item>
  278. <title>Test</title>
  279. <link>https://example.org/item</link>
  280. <author xmlns:author="http://www.w3.org/2005/Atom">
  281. <name>Foo Bar</name>
  282. <title>Vice President</title>
  283. <department/>
  284. <company>FooBar Inc.</company>
  285. </author>
  286. </item>
  287. </channel>
  288. </rss>`
  289. feed, err := Parse(bytes.NewBufferString(data))
  290. if err != nil {
  291. t.Fatal(err)
  292. }
  293. expected := "Foo Bar"
  294. result := feed.Entries[0].Author
  295. if result != expected {
  296. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  297. }
  298. }
  299. func TestParseEntryWithAtomAuthorEmail(t *testing.T) {
  300. data := `<?xml version="1.0" encoding="utf-8"?>
  301. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  302. <channel>
  303. <title>Example</title>
  304. <link>https://example.org/</link>
  305. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  306. <item>
  307. <title>Test</title>
  308. <link>https://example.org/item</link>
  309. <atom:author>
  310. <email>author@example.org</email>
  311. </atom:author>
  312. </item>
  313. </channel>
  314. </rss>`
  315. feed, err := Parse(bytes.NewBufferString(data))
  316. if err != nil {
  317. t.Fatal(err)
  318. }
  319. expected := "author@example.org"
  320. result := feed.Entries[0].Author
  321. if result != expected {
  322. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  323. }
  324. }
  325. func TestParseEntryWithAtomAuthor(t *testing.T) {
  326. data := `<?xml version="1.0" encoding="utf-8"?>
  327. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  328. <channel>
  329. <title>Example</title>
  330. <link>https://example.org/</link>
  331. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  332. <item>
  333. <title>Test</title>
  334. <link>https://example.org/item</link>
  335. <atom:author>
  336. <name>Foo Bar</name>
  337. </atom:author>
  338. </item>
  339. </channel>
  340. </rss>`
  341. feed, err := Parse(bytes.NewBufferString(data))
  342. if err != nil {
  343. t.Fatal(err)
  344. }
  345. expected := "Foo Bar"
  346. result := feed.Entries[0].Author
  347. if result != expected {
  348. t.Errorf("Incorrect entry author, got: %q instead of %q", result, expected)
  349. }
  350. }
  351. func TestParseEntryWithDublinCoreAuthor(t *testing.T) {
  352. data := `<?xml version="1.0" encoding="utf-8"?>
  353. <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  354. <channel>
  355. <title>Example</title>
  356. <link>https://example.org/</link>
  357. <item>
  358. <title>Test</title>
  359. <link>https://example.org/item</link>
  360. <dc:creator>Me (me@example.com)</dc:creator>
  361. </item>
  362. </channel>
  363. </rss>`
  364. feed, err := Parse(bytes.NewBufferString(data))
  365. if err != nil {
  366. t.Fatal(err)
  367. }
  368. expected := "Me (me@example.com)"
  369. result := feed.Entries[0].Author
  370. if result != expected {
  371. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  372. }
  373. }
  374. func TestParseEntryWithItunesAuthor(t *testing.T) {
  375. data := `<?xml version="1.0" encoding="utf-8"?>
  376. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  377. <channel>
  378. <title>Example</title>
  379. <link>https://example.org/</link>
  380. <item>
  381. <title>Test</title>
  382. <link>https://example.org/item</link>
  383. <itunes:author>Someone</itunes:author>
  384. </item>
  385. </channel>
  386. </rss>`
  387. feed, err := Parse(bytes.NewBufferString(data))
  388. if err != nil {
  389. t.Fatal(err)
  390. }
  391. expected := "Someone"
  392. result := feed.Entries[0].Author
  393. if result != expected {
  394. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  395. }
  396. }
  397. func TestParseFeedWithItunesAuthor(t *testing.T) {
  398. data := `<?xml version="1.0" encoding="utf-8"?>
  399. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  400. <channel>
  401. <title>Example</title>
  402. <link>https://example.org/</link>
  403. <itunes:author>Someone</itunes:author>
  404. <item>
  405. <title>Test</title>
  406. <link>https://example.org/item</link>
  407. </item>
  408. </channel>
  409. </rss>`
  410. feed, err := Parse(bytes.NewBufferString(data))
  411. if err != nil {
  412. t.Fatal(err)
  413. }
  414. expected := "Someone"
  415. result := feed.Entries[0].Author
  416. if result != expected {
  417. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  418. }
  419. }
  420. func TestParseFeedWithItunesOwner(t *testing.T) {
  421. data := `<?xml version="1.0" encoding="utf-8"?>
  422. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  423. <channel>
  424. <title>Example</title>
  425. <link>https://example.org/</link>
  426. <itunes:owner>
  427. <itunes:name>John Doe</itunes:name>
  428. <itunes:email>john.doe@example.com</itunes:email>
  429. </itunes:owner>
  430. <item>
  431. <title>Test</title>
  432. <link>https://example.org/item</link>
  433. </item>
  434. </channel>
  435. </rss>`
  436. feed, err := Parse(bytes.NewBufferString(data))
  437. if err != nil {
  438. t.Fatal(err)
  439. }
  440. expected := "John Doe"
  441. result := feed.Entries[0].Author
  442. if result != expected {
  443. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  444. }
  445. }
  446. func TestParseFeedWithItunesOwnerEmail(t *testing.T) {
  447. data := `<?xml version="1.0" encoding="utf-8"?>
  448. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  449. <channel>
  450. <title>Example</title>
  451. <link>https://example.org/</link>
  452. <itunes:owner>
  453. <itunes:email>john.doe@example.com</itunes:email>
  454. </itunes:owner>
  455. <item>
  456. <title>Test</title>
  457. <link>https://example.org/item</link>
  458. </item>
  459. </channel>
  460. </rss>`
  461. feed, err := Parse(bytes.NewBufferString(data))
  462. if err != nil {
  463. t.Fatal(err)
  464. }
  465. expected := "john.doe@example.com"
  466. result := feed.Entries[0].Author
  467. if result != expected {
  468. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  469. }
  470. }
  471. func TestParseEntryWithGooglePlayAuthor(t *testing.T) {
  472. data := `<?xml version="1.0" encoding="utf-8"?>
  473. <rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">
  474. <channel>
  475. <title>Example</title>
  476. <link>https://example.org/</link>
  477. <item>
  478. <title>Test</title>
  479. <link>https://example.org/item</link>
  480. <googleplay:author>Someone</googleplay:author>
  481. </item>
  482. </channel>
  483. </rss>`
  484. feed, err := Parse(bytes.NewBufferString(data))
  485. if err != nil {
  486. t.Fatal(err)
  487. }
  488. expected := "Someone"
  489. result := feed.Entries[0].Author
  490. if result != expected {
  491. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  492. }
  493. }
  494. func TestParseFeedWithGooglePlayAuthor(t *testing.T) {
  495. data := `<?xml version="1.0" encoding="utf-8"?>
  496. <rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">
  497. <channel>
  498. <title>Example</title>
  499. <link>https://example.org/</link>
  500. <googleplay:author>Someone</googleplay:author>
  501. <item>
  502. <title>Test</title>
  503. <link>https://example.org/item</link>
  504. </item>
  505. </channel>
  506. </rss>`
  507. feed, err := Parse(bytes.NewBufferString(data))
  508. if err != nil {
  509. t.Fatal(err)
  510. }
  511. expected := "Someone"
  512. result := feed.Entries[0].Author
  513. if result != expected {
  514. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  515. }
  516. }
  517. func TestParseEntryWithDublinCoreDate(t *testing.T) {
  518. data := `<?xml version="1.0" encoding="utf-8"?>
  519. <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  520. <channel>
  521. <title>Example</title>
  522. <link>http://example.org/</link>
  523. <item>
  524. <title>Item 1</title>
  525. <link>http://example.org/item1</link>
  526. <description>Description.</description>
  527. <guid isPermaLink="false">UUID</guid>
  528. <dc:date>2002-09-29T23:40:06-05:00</dc:date>
  529. </item>
  530. </channel>
  531. </rss>`
  532. feed, err := Parse(bytes.NewBufferString(data))
  533. if err != nil {
  534. t.Fatal(err)
  535. }
  536. location, _ := time.LoadLocation("EST")
  537. expectedDate := time.Date(2002, time.September, 29, 23, 40, 06, 0, location)
  538. if !feed.Entries[0].Date.Equal(expectedDate) {
  539. t.Errorf("Incorrect entry date, got: %v, want: %v", feed.Entries[0].Date, expectedDate)
  540. }
  541. }
  542. func TestParseEntryWithContentEncoded(t *testing.T) {
  543. data := `<?xml version="1.0" encoding="utf-8"?>
  544. <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  545. <channel>
  546. <title>Example</title>
  547. <link>http://example.org/</link>
  548. <item>
  549. <title>Item 1</title>
  550. <link>http://example.org/item1</link>
  551. <description>Description.</description>
  552. <guid isPermaLink="false">UUID</guid>
  553. <content:encoded><![CDATA[<p><a href="http://www.example.org/">Example</a>.</p>]]></content:encoded>
  554. </item>
  555. </channel>
  556. </rss>`
  557. feed, err := Parse(bytes.NewBufferString(data))
  558. if err != nil {
  559. t.Fatal(err)
  560. }
  561. if feed.Entries[0].Content != `<p><a href="http://www.example.org/">Example</a>.</p>` {
  562. t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].Content)
  563. }
  564. }
  565. func TestParseEntryWithFeedBurnerLink(t *testing.T) {
  566. data := `<?xml version="1.0" encoding="utf-8"?>
  567. <rss version="2.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  568. <channel>
  569. <title>Example</title>
  570. <link>http://example.org/</link>
  571. <item>
  572. <title>Item 1</title>
  573. <link>http://example.org/item1</link>
  574. <feedburner:origLink>http://example.org/original</feedburner:origLink>
  575. </item>
  576. </channel>
  577. </rss>`
  578. feed, err := Parse(bytes.NewBufferString(data))
  579. if err != nil {
  580. t.Fatal(err)
  581. }
  582. if feed.Entries[0].URL != "http://example.org/original" {
  583. t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].URL)
  584. }
  585. }
  586. func TestParseEntryTitleWithWhitespaces(t *testing.T) {
  587. data := `<?xml version="1.0" encoding="utf-8"?>
  588. <rss version="2.0">
  589. <channel>
  590. <title>Example</title>
  591. <link>http://example.org</link>
  592. <item>
  593. <title>
  594. Some Title
  595. </title>
  596. <link>http://www.example.org/entries/1</link>
  597. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  598. </item>
  599. </channel>
  600. </rss>`
  601. feed, err := Parse(bytes.NewBufferString(data))
  602. if err != nil {
  603. t.Fatal(err)
  604. }
  605. if feed.Entries[0].Title != "Some Title" {
  606. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  607. }
  608. }
  609. func TestParseEntryWithEnclosures(t *testing.T) {
  610. data := `<?xml version="1.0" encoding="utf-8"?>
  611. <rss version="2.0">
  612. <channel>
  613. <title>My Podcast Feed</title>
  614. <link>http://example.org</link>
  615. <author>some.email@example.org</author>
  616. <item>
  617. <title>Podcasting with RSS</title>
  618. <link>http://www.example.org/entries/1</link>
  619. <description>An overview of RSS podcasting</description>
  620. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  621. <guid isPermaLink="true">http://www.example.org/entries/1</guid>
  622. <enclosure url="http://www.example.org/myaudiofile.mp3"
  623. length="12345"
  624. type="audio/mpeg" />
  625. </item>
  626. </channel>
  627. </rss>`
  628. feed, err := Parse(bytes.NewBufferString(data))
  629. if err != nil {
  630. t.Fatal(err)
  631. }
  632. if len(feed.Entries) != 1 {
  633. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  634. }
  635. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  636. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  637. }
  638. if len(feed.Entries[0].Enclosures) != 1 {
  639. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  640. }
  641. if feed.Entries[0].Enclosures[0].URL != "http://www.example.org/myaudiofile.mp3" {
  642. t.Errorf("Incorrect enclosure URL, got: %s", feed.Entries[0].Enclosures[0].URL)
  643. }
  644. if feed.Entries[0].Enclosures[0].MimeType != "audio/mpeg" {
  645. t.Errorf("Incorrect enclosure type, got: %s", feed.Entries[0].Enclosures[0].MimeType)
  646. }
  647. if feed.Entries[0].Enclosures[0].Size != 12345 {
  648. t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size)
  649. }
  650. }
  651. func TestParseEntryWithEmptyEnclosureURL(t *testing.T) {
  652. data := `<?xml version="1.0" encoding="utf-8"?>
  653. <rss version="2.0">
  654. <channel>
  655. <title>My Podcast Feed</title>
  656. <link>http://example.org</link>
  657. <author>some.email@example.org</author>
  658. <item>
  659. <title>Podcasting with RSS</title>
  660. <link>http://www.example.org/entries/1</link>
  661. <description>An overview of RSS podcasting</description>
  662. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  663. <guid isPermaLink="true">http://www.example.org/entries/1</guid>
  664. <enclosure url="" length="0"/>
  665. </item>
  666. </channel>
  667. </rss>`
  668. feed, err := Parse(bytes.NewBufferString(data))
  669. if err != nil {
  670. t.Fatal(err)
  671. }
  672. if len(feed.Entries) != 1 {
  673. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  674. }
  675. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  676. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  677. }
  678. if len(feed.Entries[0].Enclosures) != 0 {
  679. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  680. }
  681. }
  682. func TestParseEntryWithFeedBurnerEnclosures(t *testing.T) {
  683. data := `<?xml version="1.0" encoding="utf-8"?>
  684. <rss version="2.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  685. <channel>
  686. <title>My Example Feed</title>
  687. <link>http://example.org</link>
  688. <author>some.email@example.org</author>
  689. <item>
  690. <title>Example Item</title>
  691. <link>http://www.example.org/entries/1</link>
  692. <enclosure
  693. url="http://feedproxy.google.com/~r/example/~5/lpMyFSCvubs/File.mp3"
  694. length="76192460"
  695. type="audio/mpeg" />
  696. <feedburner:origEnclosureLink>http://example.org/67ca416c-f22a-4228-a681-68fc9998ec10/File.mp3</feedburner:origEnclosureLink>
  697. </item>
  698. </channel>
  699. </rss>`
  700. feed, err := Parse(bytes.NewBufferString(data))
  701. if err != nil {
  702. t.Fatal(err)
  703. }
  704. if len(feed.Entries) != 1 {
  705. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  706. }
  707. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  708. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  709. }
  710. if len(feed.Entries[0].Enclosures) != 1 {
  711. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  712. }
  713. if feed.Entries[0].Enclosures[0].URL != "http://example.org/67ca416c-f22a-4228-a681-68fc9998ec10/File.mp3" {
  714. t.Errorf("Incorrect enclosure URL, got: %s", feed.Entries[0].Enclosures[0].URL)
  715. }
  716. if feed.Entries[0].Enclosures[0].MimeType != "audio/mpeg" {
  717. t.Errorf("Incorrect enclosure type, got: %s", feed.Entries[0].Enclosures[0].MimeType)
  718. }
  719. if feed.Entries[0].Enclosures[0].Size != 76192460 {
  720. t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size)
  721. }
  722. }
  723. func TestParseEntryWithRelativeURL(t *testing.T) {
  724. data := `<?xml version="1.0" encoding="utf-8"?>
  725. <rss version="2.0">
  726. <channel>
  727. <link>https://example.org/</link>
  728. <item>
  729. <link>item.html</link>
  730. </item>
  731. </channel>
  732. </rss>`
  733. feed, err := Parse(bytes.NewBufferString(data))
  734. if err != nil {
  735. t.Fatal(err)
  736. }
  737. if feed.Entries[0].Title != "https://example.org/item.html" {
  738. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  739. }
  740. }
  741. func TestParseEntryWithCommentsURL(t *testing.T) {
  742. data := `<?xml version="1.0" encoding="utf-8"?>
  743. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  744. <channel>
  745. <link>https://example.org/</link>
  746. <item>
  747. <title>Item 1</title>
  748. <link>https://example.org/item1</link>
  749. <comments>
  750. https://example.org/comments
  751. </comments>
  752. <slash:comments>42</slash:comments>
  753. </item>
  754. </channel>
  755. </rss>`
  756. feed, err := Parse(bytes.NewBufferString(data))
  757. if err != nil {
  758. t.Fatal(err)
  759. }
  760. if feed.Entries[0].CommentsURL != "https://example.org/comments" {
  761. t.Errorf("Incorrect entry comments URL, got: %q", feed.Entries[0].CommentsURL)
  762. }
  763. }
  764. func TestParseEntryWithInvalidCommentsURL(t *testing.T) {
  765. data := `<?xml version="1.0" encoding="utf-8"?>
  766. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  767. <channel>
  768. <link>https://example.org/</link>
  769. <item>
  770. <title>Item 1</title>
  771. <link>https://example.org/item1</link>
  772. <comments>
  773. Some text
  774. </comments>
  775. </item>
  776. </channel>
  777. </rss>`
  778. feed, err := Parse(bytes.NewBufferString(data))
  779. if err != nil {
  780. t.Fatal(err)
  781. }
  782. if feed.Entries[0].CommentsURL != "" {
  783. t.Errorf("Incorrect entry comments URL, got: %q", feed.Entries[0].CommentsURL)
  784. }
  785. }
  786. func TestParseInvalidXml(t *testing.T) {
  787. data := `garbage`
  788. _, err := Parse(bytes.NewBufferString(data))
  789. if err == nil {
  790. t.Error("Parse should returns an error")
  791. }
  792. }
  793. func TestParseWithHTMLEntity(t *testing.T) {
  794. data := `<?xml version="1.0" encoding="utf-8"?>
  795. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  796. <channel>
  797. <link>https://example.org/</link>
  798. <title>Example &nbsp; Feed</title>
  799. </channel>
  800. </rss>`
  801. feed, err := Parse(bytes.NewBufferString(data))
  802. if err != nil {
  803. t.Fatal(err)
  804. }
  805. if feed.Title != "Example \u00a0 Feed" {
  806. t.Errorf(`Incorrect title, got: %q`, feed.Title)
  807. }
  808. }
  809. func TestParseWithInvalidCharacterEntity(t *testing.T) {
  810. data := `<?xml version="1.0" encoding="utf-8"?>
  811. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  812. <channel>
  813. <link>https://example.org/a&b</link>
  814. <title>Example Feed</title>
  815. </channel>
  816. </rss>`
  817. feed, err := Parse(bytes.NewBufferString(data))
  818. if err != nil {
  819. t.Fatal(err)
  820. }
  821. if feed.SiteURL != "https://example.org/a&b" {
  822. t.Errorf(`Incorrect url, got: %q`, feed.SiteURL)
  823. }
  824. }
  825. func TestParseEntryWithMediaGroup(t *testing.T) {
  826. data := `<?xml version="1.0" encoding="utf-8"?>
  827. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
  828. <channel>
  829. <title>My Example Feed</title>
  830. <link>http://example.org</link>
  831. <item>
  832. <title>Example Item</title>
  833. <link>http://www.example.org/entries/1</link>
  834. <enclosure type="application/x-bittorrent" url="https://example.org/file3.torrent" length="670053113">
  835. </enclosure>
  836. <media:group>
  837. <media:content type="application/x-bittorrent" url="https://example.org/file1.torrent"></media:content>
  838. <media:content type="application/x-bittorrent" url="https://example.org/file2.torrent" isDefault="true"></media:content>
  839. <media:content type="application/x-bittorrent" url="https://example.org/file3.torrent"></media:content>
  840. <media:content type="application/x-bittorrent" url="https://example.org/file4.torrent"></media:content>
  841. <media:content type="application/x-bittorrent" url="https://example.org/file5.torrent" fileSize="42"></media:content>
  842. <media:rating>nonadult</media:rating>
  843. </media:group>
  844. <media:thumbnail url="https://example.org/image.jpg" height="122" width="223"></media:thumbnail>
  845. </item>
  846. </channel>
  847. </rss>`
  848. feed, err := Parse(bytes.NewBufferString(data))
  849. if err != nil {
  850. t.Fatal(err)
  851. }
  852. if len(feed.Entries) != 1 {
  853. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  854. }
  855. if len(feed.Entries[0].Enclosures) != 6 {
  856. t.Fatalf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  857. }
  858. expectedResults := []struct {
  859. url string
  860. mimeType string
  861. size int64
  862. }{
  863. {"https://example.org/image.jpg", "image/*", 0},
  864. {"https://example.org/file3.torrent", "application/x-bittorrent", 670053113},
  865. {"https://example.org/file1.torrent", "application/x-bittorrent", 0},
  866. {"https://example.org/file2.torrent", "application/x-bittorrent", 0},
  867. {"https://example.org/file4.torrent", "application/x-bittorrent", 0},
  868. {"https://example.org/file5.torrent", "application/x-bittorrent", 42},
  869. }
  870. for index, enclosure := range feed.Entries[0].Enclosures {
  871. if expectedResults[index].url != enclosure.URL {
  872. t.Errorf(`Unexpected enclosure URL, got %q instead of %q`, enclosure.URL, expectedResults[index].url)
  873. }
  874. if expectedResults[index].mimeType != enclosure.MimeType {
  875. t.Errorf(`Unexpected enclosure type, got %q instead of %q`, enclosure.MimeType, expectedResults[index].mimeType)
  876. }
  877. if expectedResults[index].size != enclosure.Size {
  878. t.Errorf(`Unexpected enclosure size, got %d instead of %d`, enclosure.Size, expectedResults[index].size)
  879. }
  880. }
  881. }
  882. func TestParseEntryWithMediaContent(t *testing.T) {
  883. data := `<?xml version="1.0" encoding="utf-8"?>
  884. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
  885. <channel>
  886. <title>My Example Feed</title>
  887. <link>http://example.org</link>
  888. <item>
  889. <title>Example Item</title>
  890. <link>http://www.example.org/entries/1</link>
  891. <media:thumbnail url="https://example.org/thumbnail.jpg" />
  892. <media:content url="https://example.org/media1.jpg" medium="image">
  893. <media:title type="html">Some Title for Media 1</media:title>
  894. </media:content>
  895. <media:content url="https://example.org/media2.jpg" medium="image" />
  896. </item>
  897. </channel>
  898. </rss>`
  899. feed, err := Parse(bytes.NewBufferString(data))
  900. if err != nil {
  901. t.Fatal(err)
  902. }
  903. if len(feed.Entries) != 1 {
  904. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  905. }
  906. if len(feed.Entries[0].Enclosures) != 3 {
  907. t.Fatalf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  908. }
  909. expectedResults := []struct {
  910. url string
  911. mimeType string
  912. size int64
  913. }{
  914. {"https://example.org/thumbnail.jpg", "image/*", 0},
  915. {"https://example.org/media1.jpg", "image/*", 0},
  916. {"https://example.org/media2.jpg", "image/*", 0},
  917. }
  918. for index, enclosure := range feed.Entries[0].Enclosures {
  919. if expectedResults[index].url != enclosure.URL {
  920. t.Errorf(`Unexpected enclosure URL, got %q instead of %q`, enclosure.URL, expectedResults[index].url)
  921. }
  922. if expectedResults[index].mimeType != enclosure.MimeType {
  923. t.Errorf(`Unexpected enclosure type, got %q instead of %q`, enclosure.MimeType, expectedResults[index].mimeType)
  924. }
  925. if expectedResults[index].size != enclosure.Size {
  926. t.Errorf(`Unexpected enclosure size, got %d instead of %d`, enclosure.Size, expectedResults[index].size)
  927. }
  928. }
  929. }
  930. func TestParseEntryWithMediaPeerLink(t *testing.T) {
  931. data := `<?xml version="1.0" encoding="utf-8"?>
  932. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
  933. <channel>
  934. <title>My Example Feed</title>
  935. <link>http://example.org</link>
  936. <item>
  937. <title>Example Item</title>
  938. <link>http://www.example.org/entries/1</link>
  939. <media:peerLink type="application/x-bittorrent" href="http://www.example.org/file.torrent" />
  940. </item>
  941. </channel>
  942. </rss>`
  943. feed, err := Parse(bytes.NewBufferString(data))
  944. if err != nil {
  945. t.Fatal(err)
  946. }
  947. if len(feed.Entries) != 1 {
  948. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  949. }
  950. if len(feed.Entries[0].Enclosures) != 1 {
  951. t.Fatalf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  952. }
  953. expectedResults := []struct {
  954. url string
  955. mimeType string
  956. size int64
  957. }{
  958. {"http://www.example.org/file.torrent", "application/x-bittorrent", 0},
  959. }
  960. for index, enclosure := range feed.Entries[0].Enclosures {
  961. if expectedResults[index].url != enclosure.URL {
  962. t.Errorf(`Unexpected enclosure URL, got %q instead of %q`, enclosure.URL, expectedResults[index].url)
  963. }
  964. if expectedResults[index].mimeType != enclosure.MimeType {
  965. t.Errorf(`Unexpected enclosure type, got %q instead of %q`, enclosure.MimeType, expectedResults[index].mimeType)
  966. }
  967. if expectedResults[index].size != enclosure.Size {
  968. t.Errorf(`Unexpected enclosure size, got %d instead of %d`, enclosure.Size, expectedResults[index].size)
  969. }
  970. }
  971. }
  972. func TestEntryDescriptionFromItunesSummary(t *testing.T) {
  973. data := `<?xml version="1.0" encoding="UTF-8"?>
  974. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  975. <channel>
  976. <title>Podcast Example</title>
  977. <link>http://www.example.com/index.html</link>
  978. <item>
  979. <title>Podcast Episode</title>
  980. <guid>http://example.com/episode.m4a</guid>
  981. <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate>
  982. <itunes:subtitle>Episode Subtitle</itunes:subtitle>
  983. <itunes:summary>Episode Summary</itunes:summary>
  984. </item>
  985. </channel>
  986. </rss>`
  987. feed, err := Parse(bytes.NewBufferString(data))
  988. if err != nil {
  989. t.Fatal(err)
  990. }
  991. if len(feed.Entries) != 1 {
  992. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  993. }
  994. expected := "Episode Summary"
  995. result := feed.Entries[0].Content
  996. if expected != result {
  997. t.Errorf(`Unexpected podcast content, got %q instead of %q`, result, expected)
  998. }
  999. }
  1000. func TestEntryDescriptionFromItunesSubtitle(t *testing.T) {
  1001. data := `<?xml version="1.0" encoding="UTF-8"?>
  1002. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  1003. <channel>
  1004. <title>Podcast Example</title>
  1005. <link>http://www.example.com/index.html</link>
  1006. <item>
  1007. <title>Podcast Episode</title>
  1008. <guid>http://example.com/episode.m4a</guid>
  1009. <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate>
  1010. <itunes:subtitle>Episode Subtitle</itunes:subtitle>
  1011. </item>
  1012. </channel>
  1013. </rss>`
  1014. feed, err := Parse(bytes.NewBufferString(data))
  1015. if err != nil {
  1016. t.Fatal(err)
  1017. }
  1018. if len(feed.Entries) != 1 {
  1019. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  1020. }
  1021. expected := "Episode Subtitle"
  1022. result := feed.Entries[0].Content
  1023. if expected != result {
  1024. t.Errorf(`Unexpected podcast content, got %q instead of %q`, result, expected)
  1025. }
  1026. }
  1027. func TestEntryDescriptionFromGooglePlayDescription(t *testing.T) {
  1028. data := `<?xml version="1.0" encoding="UTF-8"?>
  1029. <rss version="2.0"
  1030. xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"
  1031. xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  1032. <channel>
  1033. <title>Podcast Example</title>
  1034. <link>http://www.example.com/index.html</link>
  1035. <item>
  1036. <title>Podcast Episode</title>
  1037. <guid>http://example.com/episode.m4a</guid>
  1038. <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate>
  1039. <itunes:subtitle>Episode Subtitle</itunes:subtitle>
  1040. <googleplay:description>Episode Description</googleplay:description>
  1041. </item>
  1042. </channel>
  1043. </rss>`
  1044. feed, err := Parse(bytes.NewBufferString(data))
  1045. if err != nil {
  1046. t.Fatal(err)
  1047. }
  1048. if len(feed.Entries) != 1 {
  1049. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  1050. }
  1051. expected := "Episode Description"
  1052. result := feed.Entries[0].Content
  1053. if expected != result {
  1054. t.Errorf(`Unexpected podcast content, got %q instead of %q`, result, expected)
  1055. }
  1056. }