package main
import (
"testing"
"github.com/TheLovinator1/FeedVault/pkg/opml"
)
var opmlExample = `
My Feeds
`
var secondOpmlExample = `
Engineering Blogs
`
// Test the opml parser
func TestParseOpml(t *testing.T) {
links, err := opml.ParseOpml(opmlExample)
if err != nil {
t.Error(err)
}
if len(links.XMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.XMLLinks))
}
if len(links.HTMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.HTMLLinks))
}
// Test that the links are unique
links.XMLLinks = opml.RemoveDuplicates(links.XMLLinks)
links.HTMLLinks = opml.RemoveDuplicates(links.HTMLLinks)
if len(links.XMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.XMLLinks))
}
if len(links.HTMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.HTMLLinks))
}
// Test that the links are correct
if links.XMLLinks[0] != "http://feeds.feedburner.com/24ways" {
t.Errorf("Expected http://feeds.feedburner.com/24ways, got %s", links.XMLLinks[0])
}
if links.XMLLinks[1] != "http://writing.jan.io/feed.xml" {
t.Errorf("Expected http://writing.jan.io/feed.xml, got %s", links.XMLLinks[1])
}
if links.HTMLLinks[0] != "http://24ways.org/" {
t.Errorf("Expected http://24ways.org/, got %s", links.HTMLLinks[0])
}
if links.HTMLLinks[1] != "http://writing.jan.io/" {
t.Errorf("Expected http://writing.jan.io/, got %s", links.HTMLLinks[1])
}
}
// Test the opml parser with nested outlines
func TestParseOpmlNested(t *testing.T) {
links, err := opml.ParseOpml(secondOpmlExample)
if err != nil {
t.Error(err)
}
if len(links.XMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.XMLLinks))
}
if len(links.HTMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.HTMLLinks))
}
// Test that the links are unique
links.XMLLinks = opml.RemoveDuplicates(links.XMLLinks)
links.HTMLLinks = opml.RemoveDuplicates(links.HTMLLinks)
if len(links.XMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.XMLLinks))
}
if len(links.HTMLLinks) != 2 {
t.Errorf("Expected 2 links, got %d", len(links.HTMLLinks))
}
// Test that the links are correct
if links.XMLLinks[0] != "https://8thlight.com/blog/feed/atom.xml" {
t.Errorf("Expected https://8thlight.com/blog/feed/atom.xml, got %s", links.XMLLinks[0])
}
if links.XMLLinks[1] != "http://www.vertabelo.com/_rss/blog.xml" {
t.Errorf("Expected http://www.vertabelo.com/_rss/blog.xml, got %s", links.XMLLinks[1])
}
if links.HTMLLinks[0] != "https://8thlight.com/blog/" {
t.Errorf("Expected https://8thlight.com/blog/, got %s", links.HTMLLinks[0])
}
if links.HTMLLinks[1] != "http://www.vertabelo.com/blog" {
t.Errorf("Expected http://www.vertabelo.com/blog, got %s", links.HTMLLinks[1])
}
}