parser_test.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  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 TestParseEntryWithMediaTitle(t *testing.T) {
  120. data := `<?xml version="1.0" encoding="utf-8"?>
  121. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
  122. <channel>
  123. <link>https://example.org/</link>
  124. <item>
  125. <title>Entry Title</title>
  126. <link>https://example.org/item</link>
  127. <media:title>Media Title</media:title>
  128. </item>
  129. </channel>
  130. </rss>`
  131. feed, err := Parse(bytes.NewBufferString(data))
  132. if err != nil {
  133. t.Fatal(err)
  134. }
  135. if feed.Entries[0].Title != "Entry Title" {
  136. t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title)
  137. }
  138. }
  139. func TestParseEntryWithDCTitleOnly(t *testing.T) {
  140. data := `<?xml version="1.0" encoding="utf-8"?>
  141. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  142. <channel>
  143. <link>https://example.org/</link>
  144. <item>
  145. <dc:title>Entry Title</dc:title>
  146. <link>https://example.org/item</link>
  147. </item>
  148. </channel>
  149. </rss>`
  150. feed, err := Parse(bytes.NewBufferString(data))
  151. if err != nil {
  152. t.Fatal(err)
  153. }
  154. if feed.Entries[0].Title != "Entry Title" {
  155. t.Errorf("Incorrect entry title, got: %q", feed.Entries[0].Title)
  156. }
  157. }
  158. func TestParseEntryWithoutLink(t *testing.T) {
  159. data := `<?xml version="1.0" encoding="utf-8"?>
  160. <rss version="2.0">
  161. <channel>
  162. <link>https://example.org/</link>
  163. <item>
  164. <guid isPermaLink="false">1234</guid>
  165. </item>
  166. </channel>
  167. </rss>`
  168. feed, err := Parse(bytes.NewBufferString(data))
  169. if err != nil {
  170. t.Fatal(err)
  171. }
  172. if feed.Entries[0].URL != "https://example.org/" {
  173. t.Errorf("Incorrect entry link, got: %s", feed.Entries[0].URL)
  174. }
  175. if feed.Entries[0].Hash != "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4" {
  176. t.Errorf("Incorrect entry hash, got: %s", feed.Entries[0].Hash)
  177. }
  178. }
  179. func TestParseEntryWithAtomLink(t *testing.T) {
  180. data := `<?xml version="1.0" encoding="utf-8"?>
  181. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  182. <channel>
  183. <link>https://example.org/</link>
  184. <item>
  185. <title>Test</title>
  186. <atom:link href="https://example.org/item" />
  187. </item>
  188. </channel>
  189. </rss>`
  190. feed, err := Parse(bytes.NewBufferString(data))
  191. if err != nil {
  192. t.Fatal(err)
  193. }
  194. if feed.Entries[0].URL != "https://example.org/item" {
  195. t.Errorf("Incorrect entry link, got: %s", feed.Entries[0].URL)
  196. }
  197. }
  198. func TestParseEntryWithMultipleAtomLinks(t *testing.T) {
  199. data := `<?xml version="1.0" encoding="utf-8"?>
  200. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  201. <channel>
  202. <link>https://example.org/</link>
  203. <item>
  204. <title>Test</title>
  205. <atom:link rel="payment" href="https://example.org/a" />
  206. <atom:link rel="http://foobar.tld" href="https://example.org/b" />
  207. </item>
  208. </channel>
  209. </rss>`
  210. feed, err := Parse(bytes.NewBufferString(data))
  211. if err != nil {
  212. t.Fatal(err)
  213. }
  214. if feed.Entries[0].URL != "https://example.org/b" {
  215. t.Errorf("Incorrect entry link, got: %s", feed.Entries[0].URL)
  216. }
  217. }
  218. func TestParseFeedURLWithAtomLink(t *testing.T) {
  219. data := `<?xml version="1.0" encoding="utf-8"?>
  220. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  221. <channel>
  222. <title>Example</title>
  223. <link>https://example.org/</link>
  224. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  225. </channel>
  226. </rss>`
  227. feed, err := Parse(bytes.NewBufferString(data))
  228. if err != nil {
  229. t.Fatal(err)
  230. }
  231. if feed.FeedURL != "https://example.org/rss" {
  232. t.Errorf("Incorrect feed URL, got: %s", feed.FeedURL)
  233. }
  234. if feed.SiteURL != "https://example.org/" {
  235. t.Errorf("Incorrect site URL, got: %s", feed.SiteURL)
  236. }
  237. }
  238. func TestParseFeedWithWebmaster(t *testing.T) {
  239. data := `<?xml version="1.0" encoding="utf-8"?>
  240. <rss version="2.0">
  241. <channel>
  242. <title>Example</title>
  243. <link>https://example.org/</link>
  244. <webMaster>webmaster@example.com</webMaster>
  245. <item>
  246. <title>Test</title>
  247. <link>https://example.org/item</link>
  248. </item>
  249. </channel>
  250. </rss>`
  251. feed, err := Parse(bytes.NewBufferString(data))
  252. if err != nil {
  253. t.Fatal(err)
  254. }
  255. expected := "webmaster@example.com"
  256. result := feed.Entries[0].Author
  257. if result != expected {
  258. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  259. }
  260. }
  261. func TestParseFeedWithManagingEditor(t *testing.T) {
  262. data := `<?xml version="1.0" encoding="utf-8"?>
  263. <rss version="2.0">
  264. <channel>
  265. <title>Example</title>
  266. <link>https://example.org/</link>
  267. <webMaster>webmaster@example.com</webMaster>
  268. <managingEditor>editor@example.com</managingEditor>
  269. <item>
  270. <title>Test</title>
  271. <link>https://example.org/item</link>
  272. </item>
  273. </channel>
  274. </rss>`
  275. feed, err := Parse(bytes.NewBufferString(data))
  276. if err != nil {
  277. t.Fatal(err)
  278. }
  279. expected := "editor@example.com"
  280. result := feed.Entries[0].Author
  281. if result != expected {
  282. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  283. }
  284. }
  285. func TestParseEntryWithAuthorAndInnerHTML(t *testing.T) {
  286. data := `<?xml version="1.0" encoding="utf-8"?>
  287. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  288. <channel>
  289. <title>Example</title>
  290. <link>https://example.org/</link>
  291. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  292. <item>
  293. <title>Test</title>
  294. <link>https://example.org/item</link>
  295. <author>by <a itemprop="url" class="author" rel="author" href="/author/foobar">Foo Bar</a></author>
  296. </item>
  297. </channel>
  298. </rss>`
  299. feed, err := Parse(bytes.NewBufferString(data))
  300. if err != nil {
  301. t.Fatal(err)
  302. }
  303. expected := "by Foo Bar"
  304. result := feed.Entries[0].Author
  305. if result != expected {
  306. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  307. }
  308. }
  309. func TestParseEntryWithNonStandardAtomAuthor(t *testing.T) {
  310. data := `<?xml version="1.0" encoding="utf-8"?>
  311. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  312. <channel>
  313. <title>Example</title>
  314. <link>https://example.org/</link>
  315. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  316. <item>
  317. <title>Test</title>
  318. <link>https://example.org/item</link>
  319. <author xmlns:author="http://www.w3.org/2005/Atom">
  320. <name>Foo Bar</name>
  321. <title>Vice President</title>
  322. <department/>
  323. <company>FooBar Inc.</company>
  324. </author>
  325. </item>
  326. </channel>
  327. </rss>`
  328. feed, err := Parse(bytes.NewBufferString(data))
  329. if err != nil {
  330. t.Fatal(err)
  331. }
  332. expected := "Foo Bar"
  333. result := feed.Entries[0].Author
  334. if result != expected {
  335. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  336. }
  337. }
  338. func TestParseEntryWithAtomAuthorEmail(t *testing.T) {
  339. data := `<?xml version="1.0" encoding="utf-8"?>
  340. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  341. <channel>
  342. <title>Example</title>
  343. <link>https://example.org/</link>
  344. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  345. <item>
  346. <title>Test</title>
  347. <link>https://example.org/item</link>
  348. <atom:author>
  349. <email>author@example.org</email>
  350. </atom:author>
  351. </item>
  352. </channel>
  353. </rss>`
  354. feed, err := Parse(bytes.NewBufferString(data))
  355. if err != nil {
  356. t.Fatal(err)
  357. }
  358. expected := "author@example.org"
  359. result := feed.Entries[0].Author
  360. if result != expected {
  361. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  362. }
  363. }
  364. func TestParseEntryWithAtomAuthor(t *testing.T) {
  365. data := `<?xml version="1.0" encoding="utf-8"?>
  366. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  367. <channel>
  368. <title>Example</title>
  369. <link>https://example.org/</link>
  370. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  371. <item>
  372. <title>Test</title>
  373. <link>https://example.org/item</link>
  374. <atom:author>
  375. <name>Foo Bar</name>
  376. </atom:author>
  377. </item>
  378. </channel>
  379. </rss>`
  380. feed, err := Parse(bytes.NewBufferString(data))
  381. if err != nil {
  382. t.Fatal(err)
  383. }
  384. expected := "Foo Bar"
  385. result := feed.Entries[0].Author
  386. if result != expected {
  387. t.Errorf("Incorrect entry author, got: %q instead of %q", result, expected)
  388. }
  389. }
  390. func TestParseEntryWithDublinCoreAuthor(t *testing.T) {
  391. data := `<?xml version="1.0" encoding="utf-8"?>
  392. <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  393. <channel>
  394. <title>Example</title>
  395. <link>https://example.org/</link>
  396. <item>
  397. <title>Test</title>
  398. <link>https://example.org/item</link>
  399. <dc:creator>Me (me@example.com)</dc:creator>
  400. </item>
  401. </channel>
  402. </rss>`
  403. feed, err := Parse(bytes.NewBufferString(data))
  404. if err != nil {
  405. t.Fatal(err)
  406. }
  407. expected := "Me (me@example.com)"
  408. result := feed.Entries[0].Author
  409. if result != expected {
  410. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  411. }
  412. }
  413. func TestParseEntryWithItunesAuthor(t *testing.T) {
  414. data := `<?xml version="1.0" encoding="utf-8"?>
  415. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  416. <channel>
  417. <title>Example</title>
  418. <link>https://example.org/</link>
  419. <item>
  420. <title>Test</title>
  421. <link>https://example.org/item</link>
  422. <itunes:author>Someone</itunes:author>
  423. </item>
  424. </channel>
  425. </rss>`
  426. feed, err := Parse(bytes.NewBufferString(data))
  427. if err != nil {
  428. t.Fatal(err)
  429. }
  430. expected := "Someone"
  431. result := feed.Entries[0].Author
  432. if result != expected {
  433. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  434. }
  435. }
  436. func TestParseFeedWithItunesAuthor(t *testing.T) {
  437. data := `<?xml version="1.0" encoding="utf-8"?>
  438. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  439. <channel>
  440. <title>Example</title>
  441. <link>https://example.org/</link>
  442. <itunes:author>Someone</itunes:author>
  443. <item>
  444. <title>Test</title>
  445. <link>https://example.org/item</link>
  446. </item>
  447. </channel>
  448. </rss>`
  449. feed, err := Parse(bytes.NewBufferString(data))
  450. if err != nil {
  451. t.Fatal(err)
  452. }
  453. expected := "Someone"
  454. result := feed.Entries[0].Author
  455. if result != expected {
  456. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  457. }
  458. }
  459. func TestParseFeedWithItunesOwner(t *testing.T) {
  460. data := `<?xml version="1.0" encoding="utf-8"?>
  461. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  462. <channel>
  463. <title>Example</title>
  464. <link>https://example.org/</link>
  465. <itunes:owner>
  466. <itunes:name>John Doe</itunes:name>
  467. <itunes:email>john.doe@example.com</itunes:email>
  468. </itunes:owner>
  469. <item>
  470. <title>Test</title>
  471. <link>https://example.org/item</link>
  472. </item>
  473. </channel>
  474. </rss>`
  475. feed, err := Parse(bytes.NewBufferString(data))
  476. if err != nil {
  477. t.Fatal(err)
  478. }
  479. expected := "John Doe"
  480. result := feed.Entries[0].Author
  481. if result != expected {
  482. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  483. }
  484. }
  485. func TestParseFeedWithItunesOwnerEmail(t *testing.T) {
  486. data := `<?xml version="1.0" encoding="utf-8"?>
  487. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  488. <channel>
  489. <title>Example</title>
  490. <link>https://example.org/</link>
  491. <itunes:owner>
  492. <itunes:email>john.doe@example.com</itunes:email>
  493. </itunes:owner>
  494. <item>
  495. <title>Test</title>
  496. <link>https://example.org/item</link>
  497. </item>
  498. </channel>
  499. </rss>`
  500. feed, err := Parse(bytes.NewBufferString(data))
  501. if err != nil {
  502. t.Fatal(err)
  503. }
  504. expected := "john.doe@example.com"
  505. result := feed.Entries[0].Author
  506. if result != expected {
  507. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  508. }
  509. }
  510. func TestParseEntryWithGooglePlayAuthor(t *testing.T) {
  511. data := `<?xml version="1.0" encoding="utf-8"?>
  512. <rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">
  513. <channel>
  514. <title>Example</title>
  515. <link>https://example.org/</link>
  516. <item>
  517. <title>Test</title>
  518. <link>https://example.org/item</link>
  519. <googleplay:author>Someone</googleplay:author>
  520. </item>
  521. </channel>
  522. </rss>`
  523. feed, err := Parse(bytes.NewBufferString(data))
  524. if err != nil {
  525. t.Fatal(err)
  526. }
  527. expected := "Someone"
  528. result := feed.Entries[0].Author
  529. if result != expected {
  530. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  531. }
  532. }
  533. func TestParseFeedWithGooglePlayAuthor(t *testing.T) {
  534. data := `<?xml version="1.0" encoding="utf-8"?>
  535. <rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">
  536. <channel>
  537. <title>Example</title>
  538. <link>https://example.org/</link>
  539. <googleplay:author>Someone</googleplay:author>
  540. <item>
  541. <title>Test</title>
  542. <link>https://example.org/item</link>
  543. </item>
  544. </channel>
  545. </rss>`
  546. feed, err := Parse(bytes.NewBufferString(data))
  547. if err != nil {
  548. t.Fatal(err)
  549. }
  550. expected := "Someone"
  551. result := feed.Entries[0].Author
  552. if result != expected {
  553. t.Errorf("Incorrect entry author, got %q instead of %q", result, expected)
  554. }
  555. }
  556. func TestParseEntryWithDublinCoreDate(t *testing.T) {
  557. data := `<?xml version="1.0" encoding="utf-8"?>
  558. <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  559. <channel>
  560. <title>Example</title>
  561. <link>http://example.org/</link>
  562. <item>
  563. <title>Item 1</title>
  564. <link>http://example.org/item1</link>
  565. <description>Description.</description>
  566. <guid isPermaLink="false">UUID</guid>
  567. <dc:date>2002-09-29T23:40:06-05:00</dc:date>
  568. </item>
  569. </channel>
  570. </rss>`
  571. feed, err := Parse(bytes.NewBufferString(data))
  572. if err != nil {
  573. t.Fatal(err)
  574. }
  575. location, _ := time.LoadLocation("EST")
  576. expectedDate := time.Date(2002, time.September, 29, 23, 40, 06, 0, location)
  577. if !feed.Entries[0].Date.Equal(expectedDate) {
  578. t.Errorf("Incorrect entry date, got: %v, want: %v", feed.Entries[0].Date, expectedDate)
  579. }
  580. }
  581. func TestParseEntryWithContentEncoded(t *testing.T) {
  582. data := `<?xml version="1.0" encoding="utf-8"?>
  583. <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  584. <channel>
  585. <title>Example</title>
  586. <link>http://example.org/</link>
  587. <item>
  588. <title>Item 1</title>
  589. <link>http://example.org/item1</link>
  590. <description>Description.</description>
  591. <guid isPermaLink="false">UUID</guid>
  592. <content:encoded><![CDATA[<p><a href="http://www.example.org/">Example</a>.</p>]]></content:encoded>
  593. </item>
  594. </channel>
  595. </rss>`
  596. feed, err := Parse(bytes.NewBufferString(data))
  597. if err != nil {
  598. t.Fatal(err)
  599. }
  600. if feed.Entries[0].Content != `<p><a href="http://www.example.org/">Example</a>.</p>` {
  601. t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].Content)
  602. }
  603. }
  604. func TestParseEntryWithFeedBurnerLink(t *testing.T) {
  605. data := `<?xml version="1.0" encoding="utf-8"?>
  606. <rss version="2.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  607. <channel>
  608. <title>Example</title>
  609. <link>http://example.org/</link>
  610. <item>
  611. <title>Item 1</title>
  612. <link>http://example.org/item1</link>
  613. <feedburner:origLink>http://example.org/original</feedburner:origLink>
  614. </item>
  615. </channel>
  616. </rss>`
  617. feed, err := Parse(bytes.NewBufferString(data))
  618. if err != nil {
  619. t.Fatal(err)
  620. }
  621. if feed.Entries[0].URL != "http://example.org/original" {
  622. t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].URL)
  623. }
  624. }
  625. func TestParseEntryTitleWithWhitespaces(t *testing.T) {
  626. data := `<?xml version="1.0" encoding="utf-8"?>
  627. <rss version="2.0">
  628. <channel>
  629. <title>Example</title>
  630. <link>http://example.org</link>
  631. <item>
  632. <title>
  633. Some Title
  634. </title>
  635. <link>http://www.example.org/entries/1</link>
  636. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  637. </item>
  638. </channel>
  639. </rss>`
  640. feed, err := Parse(bytes.NewBufferString(data))
  641. if err != nil {
  642. t.Fatal(err)
  643. }
  644. if feed.Entries[0].Title != "Some Title" {
  645. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  646. }
  647. }
  648. func TestParseEntryWithEnclosures(t *testing.T) {
  649. data := `<?xml version="1.0" encoding="utf-8"?>
  650. <rss version="2.0">
  651. <channel>
  652. <title>My Podcast Feed</title>
  653. <link>http://example.org</link>
  654. <author>some.email@example.org</author>
  655. <item>
  656. <title>Podcasting with RSS</title>
  657. <link>http://www.example.org/entries/1</link>
  658. <description>An overview of RSS podcasting</description>
  659. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  660. <guid isPermaLink="true">http://www.example.org/entries/1</guid>
  661. <enclosure url="http://www.example.org/myaudiofile.mp3"
  662. length="12345"
  663. type="audio/mpeg" />
  664. </item>
  665. </channel>
  666. </rss>`
  667. feed, err := Parse(bytes.NewBufferString(data))
  668. if err != nil {
  669. t.Fatal(err)
  670. }
  671. if len(feed.Entries) != 1 {
  672. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  673. }
  674. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  675. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  676. }
  677. if len(feed.Entries[0].Enclosures) != 1 {
  678. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  679. }
  680. if feed.Entries[0].Enclosures[0].URL != "http://www.example.org/myaudiofile.mp3" {
  681. t.Errorf("Incorrect enclosure URL, got: %s", feed.Entries[0].Enclosures[0].URL)
  682. }
  683. if feed.Entries[0].Enclosures[0].MimeType != "audio/mpeg" {
  684. t.Errorf("Incorrect enclosure type, got: %s", feed.Entries[0].Enclosures[0].MimeType)
  685. }
  686. if feed.Entries[0].Enclosures[0].Size != 12345 {
  687. t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size)
  688. }
  689. }
  690. func TestParseEntryWithEmptyEnclosureURL(t *testing.T) {
  691. data := `<?xml version="1.0" encoding="utf-8"?>
  692. <rss version="2.0">
  693. <channel>
  694. <title>My Podcast Feed</title>
  695. <link>http://example.org</link>
  696. <author>some.email@example.org</author>
  697. <item>
  698. <title>Podcasting with RSS</title>
  699. <link>http://www.example.org/entries/1</link>
  700. <description>An overview of RSS podcasting</description>
  701. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  702. <guid isPermaLink="true">http://www.example.org/entries/1</guid>
  703. <enclosure url="" length="0"/>
  704. </item>
  705. </channel>
  706. </rss>`
  707. feed, err := Parse(bytes.NewBufferString(data))
  708. if err != nil {
  709. t.Fatal(err)
  710. }
  711. if len(feed.Entries) != 1 {
  712. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  713. }
  714. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  715. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  716. }
  717. if len(feed.Entries[0].Enclosures) != 0 {
  718. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  719. }
  720. }
  721. func TestParseEntryWithFeedBurnerEnclosures(t *testing.T) {
  722. data := `<?xml version="1.0" encoding="utf-8"?>
  723. <rss version="2.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  724. <channel>
  725. <title>My Example Feed</title>
  726. <link>http://example.org</link>
  727. <author>some.email@example.org</author>
  728. <item>
  729. <title>Example Item</title>
  730. <link>http://www.example.org/entries/1</link>
  731. <enclosure
  732. url="http://feedproxy.google.com/~r/example/~5/lpMyFSCvubs/File.mp3"
  733. length="76192460"
  734. type="audio/mpeg" />
  735. <feedburner:origEnclosureLink>http://example.org/67ca416c-f22a-4228-a681-68fc9998ec10/File.mp3</feedburner:origEnclosureLink>
  736. </item>
  737. </channel>
  738. </rss>`
  739. feed, err := Parse(bytes.NewBufferString(data))
  740. if err != nil {
  741. t.Fatal(err)
  742. }
  743. if len(feed.Entries) != 1 {
  744. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  745. }
  746. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  747. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  748. }
  749. if len(feed.Entries[0].Enclosures) != 1 {
  750. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  751. }
  752. if feed.Entries[0].Enclosures[0].URL != "http://example.org/67ca416c-f22a-4228-a681-68fc9998ec10/File.mp3" {
  753. t.Errorf("Incorrect enclosure URL, got: %s", feed.Entries[0].Enclosures[0].URL)
  754. }
  755. if feed.Entries[0].Enclosures[0].MimeType != "audio/mpeg" {
  756. t.Errorf("Incorrect enclosure type, got: %s", feed.Entries[0].Enclosures[0].MimeType)
  757. }
  758. if feed.Entries[0].Enclosures[0].Size != 76192460 {
  759. t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size)
  760. }
  761. }
  762. func TestParseEntryWithRelativeURL(t *testing.T) {
  763. data := `<?xml version="1.0" encoding="utf-8"?>
  764. <rss version="2.0">
  765. <channel>
  766. <link>https://example.org/</link>
  767. <item>
  768. <link>item.html</link>
  769. </item>
  770. </channel>
  771. </rss>`
  772. feed, err := Parse(bytes.NewBufferString(data))
  773. if err != nil {
  774. t.Fatal(err)
  775. }
  776. if feed.Entries[0].Title != "https://example.org/item.html" {
  777. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  778. }
  779. }
  780. func TestParseEntryWithCommentsURL(t *testing.T) {
  781. data := `<?xml version="1.0" encoding="utf-8"?>
  782. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  783. <channel>
  784. <link>https://example.org/</link>
  785. <item>
  786. <title>Item 1</title>
  787. <link>https://example.org/item1</link>
  788. <comments>
  789. https://example.org/comments
  790. </comments>
  791. <slash:comments>42</slash:comments>
  792. </item>
  793. </channel>
  794. </rss>`
  795. feed, err := Parse(bytes.NewBufferString(data))
  796. if err != nil {
  797. t.Fatal(err)
  798. }
  799. if feed.Entries[0].CommentsURL != "https://example.org/comments" {
  800. t.Errorf("Incorrect entry comments URL, got: %q", feed.Entries[0].CommentsURL)
  801. }
  802. }
  803. func TestParseEntryWithInvalidCommentsURL(t *testing.T) {
  804. data := `<?xml version="1.0" encoding="utf-8"?>
  805. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  806. <channel>
  807. <link>https://example.org/</link>
  808. <item>
  809. <title>Item 1</title>
  810. <link>https://example.org/item1</link>
  811. <comments>
  812. Some text
  813. </comments>
  814. </item>
  815. </channel>
  816. </rss>`
  817. feed, err := Parse(bytes.NewBufferString(data))
  818. if err != nil {
  819. t.Fatal(err)
  820. }
  821. if feed.Entries[0].CommentsURL != "" {
  822. t.Errorf("Incorrect entry comments URL, got: %q", feed.Entries[0].CommentsURL)
  823. }
  824. }
  825. func TestParseInvalidXml(t *testing.T) {
  826. data := `garbage`
  827. _, err := Parse(bytes.NewBufferString(data))
  828. if err == nil {
  829. t.Error("Parse should returns an error")
  830. }
  831. }
  832. func TestParseWithHTMLEntity(t *testing.T) {
  833. data := `<?xml version="1.0" encoding="utf-8"?>
  834. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  835. <channel>
  836. <link>https://example.org/</link>
  837. <title>Example &nbsp; Feed</title>
  838. </channel>
  839. </rss>`
  840. feed, err := Parse(bytes.NewBufferString(data))
  841. if err != nil {
  842. t.Fatal(err)
  843. }
  844. if feed.Title != "Example \u00a0 Feed" {
  845. t.Errorf(`Incorrect title, got: %q`, feed.Title)
  846. }
  847. }
  848. func TestParseWithInvalidCharacterEntity(t *testing.T) {
  849. data := `<?xml version="1.0" encoding="utf-8"?>
  850. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  851. <channel>
  852. <link>https://example.org/a&b</link>
  853. <title>Example Feed</title>
  854. </channel>
  855. </rss>`
  856. feed, err := Parse(bytes.NewBufferString(data))
  857. if err != nil {
  858. t.Fatal(err)
  859. }
  860. if feed.SiteURL != "https://example.org/a&b" {
  861. t.Errorf(`Incorrect url, got: %q`, feed.SiteURL)
  862. }
  863. }
  864. func TestParseEntryWithMediaGroup(t *testing.T) {
  865. data := `<?xml version="1.0" encoding="utf-8"?>
  866. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
  867. <channel>
  868. <title>My Example Feed</title>
  869. <link>http://example.org</link>
  870. <item>
  871. <title>Example Item</title>
  872. <link>http://www.example.org/entries/1</link>
  873. <enclosure type="application/x-bittorrent" url="https://example.org/file3.torrent" length="670053113">
  874. </enclosure>
  875. <media:group>
  876. <media:content type="application/x-bittorrent" url="https://example.org/file1.torrent"></media:content>
  877. <media:content type="application/x-bittorrent" url="https://example.org/file2.torrent" isDefault="true"></media:content>
  878. <media:content type="application/x-bittorrent" url="https://example.org/file3.torrent"></media:content>
  879. <media:content type="application/x-bittorrent" url="https://example.org/file4.torrent"></media:content>
  880. <media:content type="application/x-bittorrent" url="https://example.org/file5.torrent" fileSize="42"></media:content>
  881. <media:rating>nonadult</media:rating>
  882. </media:group>
  883. <media:thumbnail url="https://example.org/image.jpg" height="122" width="223"></media:thumbnail>
  884. </item>
  885. </channel>
  886. </rss>`
  887. feed, err := Parse(bytes.NewBufferString(data))
  888. if err != nil {
  889. t.Fatal(err)
  890. }
  891. if len(feed.Entries) != 1 {
  892. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  893. }
  894. if len(feed.Entries[0].Enclosures) != 6 {
  895. t.Fatalf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  896. }
  897. expectedResults := []struct {
  898. url string
  899. mimeType string
  900. size int64
  901. }{
  902. {"https://example.org/image.jpg", "image/*", 0},
  903. {"https://example.org/file3.torrent", "application/x-bittorrent", 670053113},
  904. {"https://example.org/file1.torrent", "application/x-bittorrent", 0},
  905. {"https://example.org/file2.torrent", "application/x-bittorrent", 0},
  906. {"https://example.org/file4.torrent", "application/x-bittorrent", 0},
  907. {"https://example.org/file5.torrent", "application/x-bittorrent", 42},
  908. }
  909. for index, enclosure := range feed.Entries[0].Enclosures {
  910. if expectedResults[index].url != enclosure.URL {
  911. t.Errorf(`Unexpected enclosure URL, got %q instead of %q`, enclosure.URL, expectedResults[index].url)
  912. }
  913. if expectedResults[index].mimeType != enclosure.MimeType {
  914. t.Errorf(`Unexpected enclosure type, got %q instead of %q`, enclosure.MimeType, expectedResults[index].mimeType)
  915. }
  916. if expectedResults[index].size != enclosure.Size {
  917. t.Errorf(`Unexpected enclosure size, got %d instead of %d`, enclosure.Size, expectedResults[index].size)
  918. }
  919. }
  920. }
  921. func TestParseEntryWithMediaContent(t *testing.T) {
  922. data := `<?xml version="1.0" encoding="utf-8"?>
  923. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
  924. <channel>
  925. <title>My Example Feed</title>
  926. <link>http://example.org</link>
  927. <item>
  928. <title>Example Item</title>
  929. <link>http://www.example.org/entries/1</link>
  930. <media:thumbnail url="https://example.org/thumbnail.jpg" />
  931. <media:content url="https://example.org/media1.jpg" medium="image">
  932. <media:title type="html">Some Title for Media 1</media:title>
  933. </media:content>
  934. <media:content url="https://example.org/media2.jpg" medium="image" />
  935. </item>
  936. </channel>
  937. </rss>`
  938. feed, err := Parse(bytes.NewBufferString(data))
  939. if err != nil {
  940. t.Fatal(err)
  941. }
  942. if len(feed.Entries) != 1 {
  943. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  944. }
  945. if len(feed.Entries[0].Enclosures) != 3 {
  946. t.Fatalf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  947. }
  948. expectedResults := []struct {
  949. url string
  950. mimeType string
  951. size int64
  952. }{
  953. {"https://example.org/thumbnail.jpg", "image/*", 0},
  954. {"https://example.org/media1.jpg", "image/*", 0},
  955. {"https://example.org/media2.jpg", "image/*", 0},
  956. }
  957. for index, enclosure := range feed.Entries[0].Enclosures {
  958. if expectedResults[index].url != enclosure.URL {
  959. t.Errorf(`Unexpected enclosure URL, got %q instead of %q`, enclosure.URL, expectedResults[index].url)
  960. }
  961. if expectedResults[index].mimeType != enclosure.MimeType {
  962. t.Errorf(`Unexpected enclosure type, got %q instead of %q`, enclosure.MimeType, expectedResults[index].mimeType)
  963. }
  964. if expectedResults[index].size != enclosure.Size {
  965. t.Errorf(`Unexpected enclosure size, got %d instead of %d`, enclosure.Size, expectedResults[index].size)
  966. }
  967. }
  968. }
  969. func TestParseEntryWithMediaPeerLink(t *testing.T) {
  970. data := `<?xml version="1.0" encoding="utf-8"?>
  971. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
  972. <channel>
  973. <title>My Example Feed</title>
  974. <link>http://example.org</link>
  975. <item>
  976. <title>Example Item</title>
  977. <link>http://www.example.org/entries/1</link>
  978. <media:peerLink type="application/x-bittorrent" href="http://www.example.org/file.torrent" />
  979. </item>
  980. </channel>
  981. </rss>`
  982. feed, err := Parse(bytes.NewBufferString(data))
  983. if err != nil {
  984. t.Fatal(err)
  985. }
  986. if len(feed.Entries) != 1 {
  987. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  988. }
  989. if len(feed.Entries[0].Enclosures) != 1 {
  990. t.Fatalf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  991. }
  992. expectedResults := []struct {
  993. url string
  994. mimeType string
  995. size int64
  996. }{
  997. {"http://www.example.org/file.torrent", "application/x-bittorrent", 0},
  998. }
  999. for index, enclosure := range feed.Entries[0].Enclosures {
  1000. if expectedResults[index].url != enclosure.URL {
  1001. t.Errorf(`Unexpected enclosure URL, got %q instead of %q`, enclosure.URL, expectedResults[index].url)
  1002. }
  1003. if expectedResults[index].mimeType != enclosure.MimeType {
  1004. t.Errorf(`Unexpected enclosure type, got %q instead of %q`, enclosure.MimeType, expectedResults[index].mimeType)
  1005. }
  1006. if expectedResults[index].size != enclosure.Size {
  1007. t.Errorf(`Unexpected enclosure size, got %d instead of %d`, enclosure.Size, expectedResults[index].size)
  1008. }
  1009. }
  1010. }
  1011. func TestEntryDescriptionFromItunesSummary(t *testing.T) {
  1012. data := `<?xml version="1.0" encoding="UTF-8"?>
  1013. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  1014. <channel>
  1015. <title>Podcast Example</title>
  1016. <link>http://www.example.com/index.html</link>
  1017. <item>
  1018. <title>Podcast Episode</title>
  1019. <guid>http://example.com/episode.m4a</guid>
  1020. <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate>
  1021. <itunes:subtitle>Episode Subtitle</itunes:subtitle>
  1022. <itunes:summary>Episode Summary</itunes:summary>
  1023. </item>
  1024. </channel>
  1025. </rss>`
  1026. feed, err := Parse(bytes.NewBufferString(data))
  1027. if err != nil {
  1028. t.Fatal(err)
  1029. }
  1030. if len(feed.Entries) != 1 {
  1031. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  1032. }
  1033. expected := "Episode Summary"
  1034. result := feed.Entries[0].Content
  1035. if expected != result {
  1036. t.Errorf(`Unexpected podcast content, got %q instead of %q`, result, expected)
  1037. }
  1038. }
  1039. func TestEntryDescriptionFromItunesSubtitle(t *testing.T) {
  1040. data := `<?xml version="1.0" encoding="UTF-8"?>
  1041. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  1042. <channel>
  1043. <title>Podcast Example</title>
  1044. <link>http://www.example.com/index.html</link>
  1045. <item>
  1046. <title>Podcast Episode</title>
  1047. <guid>http://example.com/episode.m4a</guid>
  1048. <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate>
  1049. <itunes:subtitle>Episode Subtitle</itunes:subtitle>
  1050. </item>
  1051. </channel>
  1052. </rss>`
  1053. feed, err := Parse(bytes.NewBufferString(data))
  1054. if err != nil {
  1055. t.Fatal(err)
  1056. }
  1057. if len(feed.Entries) != 1 {
  1058. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  1059. }
  1060. expected := "Episode Subtitle"
  1061. result := feed.Entries[0].Content
  1062. if expected != result {
  1063. t.Errorf(`Unexpected podcast content, got %q instead of %q`, result, expected)
  1064. }
  1065. }
  1066. func TestEntryDescriptionFromGooglePlayDescription(t *testing.T) {
  1067. data := `<?xml version="1.0" encoding="UTF-8"?>
  1068. <rss version="2.0"
  1069. xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"
  1070. xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  1071. <channel>
  1072. <title>Podcast Example</title>
  1073. <link>http://www.example.com/index.html</link>
  1074. <item>
  1075. <title>Podcast Episode</title>
  1076. <guid>http://example.com/episode.m4a</guid>
  1077. <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate>
  1078. <itunes:subtitle>Episode Subtitle</itunes:subtitle>
  1079. <googleplay:description>Episode Description</googleplay:description>
  1080. </item>
  1081. </channel>
  1082. </rss>`
  1083. feed, err := Parse(bytes.NewBufferString(data))
  1084. if err != nil {
  1085. t.Fatal(err)
  1086. }
  1087. if len(feed.Entries) != 1 {
  1088. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  1089. }
  1090. expected := "Episode Description"
  1091. result := feed.Entries[0].Content
  1092. if expected != result {
  1093. t.Errorf(`Unexpected podcast content, got %q instead of %q`, result, expected)
  1094. }
  1095. }