format_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package parser // import "miniflux.app/v2/internal/reader/parser"
  4. import (
  5. "testing"
  6. )
  7. func TestDetectRDF(t *testing.T) {
  8. 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>`
  9. format := DetectFeedFormat(data)
  10. if format != FormatRDF {
  11. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatRDF)
  12. }
  13. }
  14. func TestDetectRSS(t *testing.T) {
  15. data := `<?xml version="1.0"?><rss version="2.0"><channel></channel></rss>`
  16. format := DetectFeedFormat(data)
  17. if format != FormatRSS {
  18. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatRSS)
  19. }
  20. }
  21. func TestDetectAtom10(t *testing.T) {
  22. data := `<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"></feed>`
  23. format := DetectFeedFormat(data)
  24. if format != FormatAtom {
  25. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatAtom)
  26. }
  27. }
  28. func TestDetectAtom03(t *testing.T) {
  29. data := `<?xml version="1.0" encoding="utf-8"?><feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en"></feed>`
  30. format := DetectFeedFormat(data)
  31. if format != FormatAtom {
  32. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatAtom)
  33. }
  34. }
  35. func TestDetectAtomWithISOCharset(t *testing.T) {
  36. data := `<?xml version="1.0" encoding="ISO-8859-15"?><feed xmlns="http://www.w3.org/2005/Atom"></feed>`
  37. format := DetectFeedFormat(data)
  38. if format != FormatAtom {
  39. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatAtom)
  40. }
  41. }
  42. func TestDetectJSON(t *testing.T) {
  43. data := `
  44. {
  45. "version" : "https://jsonfeed.org/version/1",
  46. "title" : "Example"
  47. }
  48. `
  49. format := DetectFeedFormat(data)
  50. if format != FormatJSON {
  51. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatJSON)
  52. }
  53. }
  54. func TestDetectUnknown(t *testing.T) {
  55. data := `
  56. <!DOCTYPE html> <html> </html>
  57. `
  58. format := DetectFeedFormat(data)
  59. if format != FormatUnknown {
  60. t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatUnknown)
  61. }
  62. }