format_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2018 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 parser // import "miniflux.app/reader/parser"
  5. import (
  6. "testing"
  7. )
  8. func TestDetectRDF(t *testing.T) {
  9. data := `<?xml version="1.0"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://my.netscape.com/rdf/simple/0.9/"></rdf:RDF>`
  10. format := DetectFeedFormat(data)
  11. if format != FormatRDF {
  12. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatRDF)
  13. }
  14. }
  15. func TestDetectRSS(t *testing.T) {
  16. data := `<?xml version="1.0"?><rss version="2.0"><channel></channel></rss>`
  17. format := DetectFeedFormat(data)
  18. if format != FormatRSS {
  19. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatRSS)
  20. }
  21. }
  22. func TestDetectAtom(t *testing.T) {
  23. data := `<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"></feed>`
  24. format := DetectFeedFormat(data)
  25. if format != FormatAtom {
  26. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatAtom)
  27. }
  28. }
  29. func TestDetectAtomWithISOCharset(t *testing.T) {
  30. data := `<?xml version="1.0" encoding="ISO-8859-15"?><feed xmlns="http://www.w3.org/2005/Atom"></feed>`
  31. format := DetectFeedFormat(data)
  32. if format != FormatAtom {
  33. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatAtom)
  34. }
  35. }
  36. func TestDetectJSON(t *testing.T) {
  37. data := `
  38. {
  39. "version" : "https://jsonfeed.org/version/1",
  40. "title" : "Example"
  41. }
  42. `
  43. format := DetectFeedFormat(data)
  44. if format != FormatJSON {
  45. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatJSON)
  46. }
  47. }
  48. func TestDetectUnknown(t *testing.T) {
  49. data := `
  50. <!DOCTYPE html> <html> </html>
  51. `
  52. format := DetectFeedFormat(data)
  53. if format != FormatUnknown {
  54. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatUnknown)
  55. }
  56. }