parser_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package atom // import "miniflux.app/v2/internal/reader/atom"
  4. import (
  5. "bytes"
  6. "testing"
  7. )
  8. func TestDetectAtom10(t *testing.T) {
  9. data := `<?xml version="1.0" encoding="utf-8"?>
  10. <feed xmlns="http://www.w3.org/2005/Atom">
  11. <title>Example Feed</title>
  12. <link href="http://example.org/"/>
  13. <updated>2003-12-13T18:30:02Z</updated>
  14. <author>
  15. <name>John Doe</name>
  16. </author>
  17. <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
  18. <entry>
  19. <title>Atom-Powered Robots Run Amok</title>
  20. <link href="http://example.org/2003/12/13/atom03"/>
  21. <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
  22. <updated>2003-12-13T18:30:02Z</updated>
  23. <summary>Some text.</summary>
  24. </entry>
  25. </feed>`
  26. version := getAtomFeedVersion(bytes.NewBufferString(data))
  27. if version != "1.0" {
  28. t.Errorf(`Invalid Atom version detected: %s`, version)
  29. }
  30. }
  31. func TestDetectAtom03(t *testing.T) {
  32. data := `<?xml version="1.0" encoding="utf-8"?>
  33. <feed version="0.3" xmlns="http://purl.org/atom/ns#">
  34. <title>dive into mark</title>
  35. <link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
  36. <modified>2003-12-13T18:30:02Z</modified>
  37. <author><name>Mark Pilgrim</name></author>
  38. <entry>
  39. <title>Atom 0.3 snapshot</title>
  40. <link rel="alternate" type="text/html" href="http://diveintomark.org/2003/12/13/atom03"/>
  41. <id>tag:diveintomark.org,2003:3.2397</id>
  42. <issued>2003-12-13T08:29:29-04:00</issued>
  43. <modified>2003-12-13T18:30:02Z</modified>
  44. <summary type="text/plain">This is a test</summary>
  45. <content type="text/html" mode="escaped"><![CDATA[<p>HTML content</p>]]></content>
  46. </entry>
  47. </feed>`
  48. version := getAtomFeedVersion(bytes.NewBufferString(data))
  49. if version != "0.3" {
  50. t.Errorf(`Invalid Atom version detected: %s`, version)
  51. }
  52. }