4
0

parser_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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.Error(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.Error(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.Error(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.Error(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.Error(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.Error(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.Error(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 TestParseEntryWithAuthorAndInnerHTML(t *testing.T) {
  200. data := `<?xml version="1.0" encoding="utf-8"?>
  201. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  202. <channel>
  203. <title>Example</title>
  204. <link>https://example.org/</link>
  205. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  206. <item>
  207. <title>Test</title>
  208. <link>https://example.org/item</link>
  209. <author>by <a itemprop="url" class="author" rel="author" href="/author/foobar">Foo Bar</a></author>
  210. </item>
  211. </channel>
  212. </rss>`
  213. feed, err := Parse(bytes.NewBufferString(data))
  214. if err != nil {
  215. t.Error(err)
  216. }
  217. if feed.Entries[0].Author != "by Foo Bar" {
  218. t.Errorf("Incorrect entry author, got: %s", feed.Entries[0].Author)
  219. }
  220. }
  221. func TestParseEntryWithAtomAuthor(t *testing.T) {
  222. data := `<?xml version="1.0" encoding="utf-8"?>
  223. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  224. <channel>
  225. <title>Example</title>
  226. <link>https://example.org/</link>
  227. <atom:link href="https://example.org/rss" type="application/rss+xml" rel="self"></atom:link>
  228. <item>
  229. <title>Test</title>
  230. <link>https://example.org/item</link>
  231. <author xmlns:author="http://www.w3.org/2005/Atom">
  232. <name>Foo Bar</name>
  233. <title>Vice President</title>
  234. <department/>
  235. <company>FooBar Inc.</company>
  236. </author>
  237. </item>
  238. </channel>
  239. </rss>`
  240. feed, err := Parse(bytes.NewBufferString(data))
  241. if err != nil {
  242. t.Error(err)
  243. }
  244. if feed.Entries[0].Author != "Foo Bar" {
  245. t.Errorf("Incorrect entry author, got: %s", feed.Entries[0].Author)
  246. }
  247. }
  248. func TestParseEntryWithDublinCoreAuthor(t *testing.T) {
  249. data := `<?xml version="1.0" encoding="utf-8"?>
  250. <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  251. <channel>
  252. <title>Example</title>
  253. <link>https://example.org/</link>
  254. <item>
  255. <title>Test</title>
  256. <link>https://example.org/item</link>
  257. <dc:creator>Me (me@example.com)</dc:creator>
  258. </item>
  259. </channel>
  260. </rss>`
  261. feed, err := Parse(bytes.NewBufferString(data))
  262. if err != nil {
  263. t.Error(err)
  264. }
  265. if feed.Entries[0].Author != "Me (me@example.com)" {
  266. t.Errorf("Incorrect entry author, got: %s", feed.Entries[0].Author)
  267. }
  268. }
  269. func TestParseEntryWithItunesAuthor(t *testing.T) {
  270. data := `<?xml version="1.0" encoding="utf-8"?>
  271. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  272. <channel>
  273. <title>Example</title>
  274. <link>https://example.org/</link>
  275. <item>
  276. <title>Test</title>
  277. <link>https://example.org/item</link>
  278. <itunes:author>Someone</itunes:author>
  279. </item>
  280. </channel>
  281. </rss>`
  282. feed, err := Parse(bytes.NewBufferString(data))
  283. if err != nil {
  284. t.Error(err)
  285. }
  286. if feed.Entries[0].Author != "Someone" {
  287. t.Errorf("Incorrect entry author, got: %s", feed.Entries[0].Author)
  288. }
  289. }
  290. func TestParseFeedWithItunesAuthor(t *testing.T) {
  291. data := `<?xml version="1.0" encoding="utf-8"?>
  292. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  293. <channel>
  294. <title>Example</title>
  295. <link>https://example.org/</link>
  296. <itunes:author>Someone</itunes:author>
  297. <item>
  298. <title>Test</title>
  299. <link>https://example.org/item</link>
  300. </item>
  301. </channel>
  302. </rss>`
  303. feed, err := Parse(bytes.NewBufferString(data))
  304. if err != nil {
  305. t.Error(err)
  306. }
  307. if feed.Entries[0].Author != "Someone" {
  308. t.Errorf("Incorrect entry author, got: %s", feed.Entries[0].Author)
  309. }
  310. }
  311. func TestParseEntryWithDublinCoreDate(t *testing.T) {
  312. data := `<?xml version="1.0" encoding="utf-8"?>
  313. <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  314. <channel>
  315. <title>Example</title>
  316. <link>http://example.org/</link>
  317. <item>
  318. <title>Item 1</title>
  319. <link>http://example.org/item1</link>
  320. <description>Description.</description>
  321. <guid isPermaLink="false">UUID</guid>
  322. <dc:date>2002-09-29T23:40:06-05:00</dc:date>
  323. </item>
  324. </channel>
  325. </rss>`
  326. feed, err := Parse(bytes.NewBufferString(data))
  327. if err != nil {
  328. t.Error(err)
  329. }
  330. location, _ := time.LoadLocation("EST")
  331. expectedDate := time.Date(2002, time.September, 29, 23, 40, 06, 0, location)
  332. if !feed.Entries[0].Date.Equal(expectedDate) {
  333. t.Errorf("Incorrect entry date, got: %v, want: %v", feed.Entries[0].Date, expectedDate)
  334. }
  335. }
  336. func TestParseEntryWithContentEncoded(t *testing.T) {
  337. data := `<?xml version="1.0" encoding="utf-8"?>
  338. <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  339. <channel>
  340. <title>Example</title>
  341. <link>http://example.org/</link>
  342. <item>
  343. <title>Item 1</title>
  344. <link>http://example.org/item1</link>
  345. <description>Description.</description>
  346. <guid isPermaLink="false">UUID</guid>
  347. <content:encoded><![CDATA[<p><a href="http://www.example.org/">Example</a>.</p>]]></content:encoded>
  348. </item>
  349. </channel>
  350. </rss>`
  351. feed, err := Parse(bytes.NewBufferString(data))
  352. if err != nil {
  353. t.Error(err)
  354. }
  355. if feed.Entries[0].Content != `<p><a href="http://www.example.org/">Example</a>.</p>` {
  356. t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].Content)
  357. }
  358. }
  359. func TestParseEntryWithFeedBurnerLink(t *testing.T) {
  360. data := `<?xml version="1.0" encoding="utf-8"?>
  361. <rss version="2.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  362. <channel>
  363. <title>Example</title>
  364. <link>http://example.org/</link>
  365. <item>
  366. <title>Item 1</title>
  367. <link>http://example.org/item1</link>
  368. <feedburner:origLink>http://example.org/original</feedburner:origLink>
  369. </item>
  370. </channel>
  371. </rss>`
  372. feed, err := Parse(bytes.NewBufferString(data))
  373. if err != nil {
  374. t.Error(err)
  375. }
  376. if feed.Entries[0].URL != "http://example.org/original" {
  377. t.Errorf("Incorrect entry content, got: %s", feed.Entries[0].URL)
  378. }
  379. }
  380. func TestParseEntryTitleWithWhitespaces(t *testing.T) {
  381. data := `<?xml version="1.0" encoding="utf-8"?>
  382. <rss version="2.0">
  383. <channel>
  384. <title>Example</title>
  385. <link>http://example.org</link>
  386. <item>
  387. <title>
  388. Some Title
  389. </title>
  390. <link>http://www.example.org/entries/1</link>
  391. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  392. </item>
  393. </channel>
  394. </rss>`
  395. feed, err := Parse(bytes.NewBufferString(data))
  396. if err != nil {
  397. t.Error(err)
  398. }
  399. if feed.Entries[0].Title != "Some Title" {
  400. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  401. }
  402. }
  403. func TestParseEntryWithEnclosures(t *testing.T) {
  404. data := `<?xml version="1.0" encoding="utf-8"?>
  405. <rss version="2.0">
  406. <channel>
  407. <title>My Podcast Feed</title>
  408. <link>http://example.org</link>
  409. <author>some.email@example.org</author>
  410. <item>
  411. <title>Podcasting with RSS</title>
  412. <link>http://www.example.org/entries/1</link>
  413. <description>An overview of RSS podcasting</description>
  414. <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate>
  415. <guid isPermaLink="true">http://www.example.org/entries/1</guid>
  416. <enclosure url="http://www.example.org/myaudiofile.mp3"
  417. length="12345"
  418. type="audio/mpeg" />
  419. </item>
  420. </channel>
  421. </rss>`
  422. feed, err := Parse(bytes.NewBufferString(data))
  423. if err != nil {
  424. t.Error(err)
  425. }
  426. if len(feed.Entries) != 1 {
  427. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  428. }
  429. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  430. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  431. }
  432. if len(feed.Entries[0].Enclosures) != 1 {
  433. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  434. }
  435. if feed.Entries[0].Enclosures[0].URL != "http://www.example.org/myaudiofile.mp3" {
  436. t.Errorf("Incorrect enclosure URL, got: %s", feed.Entries[0].Enclosures[0].URL)
  437. }
  438. if feed.Entries[0].Enclosures[0].MimeType != "audio/mpeg" {
  439. t.Errorf("Incorrect enclosure type, got: %s", feed.Entries[0].Enclosures[0].MimeType)
  440. }
  441. if feed.Entries[0].Enclosures[0].Size != 12345 {
  442. t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size)
  443. }
  444. }
  445. func TestParseEntryWithFeedBurnerEnclosures(t *testing.T) {
  446. data := `<?xml version="1.0" encoding="utf-8"?>
  447. <rss version="2.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  448. <channel>
  449. <title>My Example Feed</title>
  450. <link>http://example.org</link>
  451. <author>some.email@example.org</author>
  452. <item>
  453. <title>Example Item</title>
  454. <link>http://www.example.org/entries/1</link>
  455. <enclosure
  456. url="http://feedproxy.google.com/~r/example/~5/lpMyFSCvubs/File.mp3"
  457. length="76192460"
  458. type="audio/mpeg" />
  459. <feedburner:origEnclosureLink>http://example.org/67ca416c-f22a-4228-a681-68fc9998ec10/File.mp3</feedburner:origEnclosureLink>
  460. </item>
  461. </channel>
  462. </rss>`
  463. feed, err := Parse(bytes.NewBufferString(data))
  464. if err != nil {
  465. t.Error(err)
  466. }
  467. if len(feed.Entries) != 1 {
  468. t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
  469. }
  470. if feed.Entries[0].URL != "http://www.example.org/entries/1" {
  471. t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
  472. }
  473. if len(feed.Entries[0].Enclosures) != 1 {
  474. t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures))
  475. }
  476. if feed.Entries[0].Enclosures[0].URL != "http://example.org/67ca416c-f22a-4228-a681-68fc9998ec10/File.mp3" {
  477. t.Errorf("Incorrect enclosure URL, got: %s", feed.Entries[0].Enclosures[0].URL)
  478. }
  479. if feed.Entries[0].Enclosures[0].MimeType != "audio/mpeg" {
  480. t.Errorf("Incorrect enclosure type, got: %s", feed.Entries[0].Enclosures[0].MimeType)
  481. }
  482. if feed.Entries[0].Enclosures[0].Size != 76192460 {
  483. t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size)
  484. }
  485. }
  486. func TestParseEntryWithRelativeURL(t *testing.T) {
  487. data := `<?xml version="1.0" encoding="utf-8"?>
  488. <rss version="2.0">
  489. <channel>
  490. <link>https://example.org/</link>
  491. <item>
  492. <link>item.html</link>
  493. </item>
  494. </channel>
  495. </rss>`
  496. feed, err := Parse(bytes.NewBufferString(data))
  497. if err != nil {
  498. t.Error(err)
  499. }
  500. if feed.Entries[0].Title != "https://example.org/item.html" {
  501. t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
  502. }
  503. }
  504. func TestParseEntryWithCommentsURL(t *testing.T) {
  505. data := `<?xml version="1.0" encoding="utf-8"?>
  506. <rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  507. <channel>
  508. <link>https://example.org/</link>
  509. <item>
  510. <title>Item 1</title>
  511. <link>https://example.org/item1</link>
  512. <comments>
  513. https://example.org/comments
  514. </comments>
  515. <slash:comments>42</slash:comments>
  516. </item>
  517. </channel>
  518. </rss>`
  519. feed, err := Parse(bytes.NewBufferString(data))
  520. if err != nil {
  521. t.Error(err)
  522. }
  523. if feed.Entries[0].CommentsURL != "https://example.org/comments" {
  524. t.Errorf("Incorrect entry comments URL, got: %q", feed.Entries[0].CommentsURL)
  525. }
  526. }
  527. func TestParseInvalidXml(t *testing.T) {
  528. data := `garbage`
  529. _, err := Parse(bytes.NewBufferString(data))
  530. if err == nil {
  531. t.Error("Parse should returns an error")
  532. }
  533. }