parser_test.go 1.9 KB

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