processor_test.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 processor // import "miniflux.app/reader/processor"
  5. import (
  6. "miniflux.app/reader/parser"
  7. "testing"
  8. )
  9. func TestKeeplistRules(t *testing.T) {
  10. data := `<?xml version="1.0"?>
  11. <rss version="2.0">
  12. <channel>
  13. <title>SomeGood News</title>
  14. <link>http://foo.bar/</link>
  15. <item>
  16. <title>Kitten News</title>
  17. <link>http://kitties.today/daily-kitten</link>
  18. <description>Kitten picture of the day.</description>
  19. <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
  20. <guid>http://kitties.today</guid>
  21. </item>
  22. <item>
  23. <title>Daily Covid DoomScrolling News</title>
  24. <link>http://covid.doom/daily-panic-dose</link>
  25. <description>Did you know that you can get COVID IN YOUR DREAMS?.</description>
  26. <pubDate>Tue, 03 Jun 2020 09:39:21 GMT</pubDate>
  27. <guid>http://covid.doom</guid>
  28. </item>
  29. </channel>
  30. </rss>`
  31. feed, err := parser.ParseFeed(data)
  32. if err != nil {
  33. t.Error(err)
  34. }
  35. if len(feed.Entries) != 2 {
  36. t.Errorf("Error parsing feed")
  37. }
  38. //case insensitive
  39. feed.KeeplistRules = "(?i)kitten"
  40. filterFeedEntries(feed)
  41. if len(feed.Entries) != 1 {
  42. t.Errorf("Keeplist filter rule did not properly filter the feed")
  43. }
  44. }
  45. func TestBlocklistRules(t *testing.T) {
  46. data := `<?xml version="1.0"?>
  47. <rss version="2.0">
  48. <channel>
  49. <title>SomeGood News</title>
  50. <link>http://foo.bar/</link>
  51. <item>
  52. <title>Kitten News</title>
  53. <link>http://kitties.today/daily-kitten</link>
  54. <description>Kitten picture of the day.</description>
  55. <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
  56. <guid>http://kitties.today</guid>
  57. </item>
  58. <item>
  59. <title>Daily Covid DoomScrolling News</title>
  60. <link>http://covid.doom/daily-panic-dose</link>
  61. <description>Did you know that you can get COVID IN YOUR DREAMS?.</description>
  62. <pubDate>Tue, 03 Jun 2020 09:39:21 GMT</pubDate>
  63. <guid>http://covid.doom</guid>
  64. </item>
  65. </channel>
  66. </rss>`
  67. feed, err := parser.ParseFeed(data)
  68. if err != nil {
  69. t.Error(err)
  70. }
  71. if len(feed.Entries) != 2 {
  72. t.Errorf("Error parsing feed")
  73. }
  74. //case insensitive
  75. feed.BlocklistRules = "(?i)covid"
  76. filterFeedEntries(feed)
  77. if len(feed.Entries) != 1 {
  78. t.Errorf("Keeplist filter rule did not properly filter the feed")
  79. }
  80. }