mirror of
https://github.com/miniflux/v2.git
synced 2025-08-16 18:01:37 +00:00
Don't use a slice of pointers to opml items, when we can simply use a slice of items instead. This should reduce the amount of memory allocations and the number of indirections the GC has to process, speedup up the import process. Note that this doesn't introduce any additional copies, as the only time a slice of subscription is created, the items are created and inserted inline.
63 lines
2.3 KiB
Go
63 lines
2.3 KiB
Go
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package opml // import "miniflux.app/v2/internal/reader/opml"
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestSerialize(t *testing.T) {
|
|
var subscriptions []subcription
|
|
subscriptions = append(subscriptions, subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
|
|
subscriptions = append(subscriptions, subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: "Category 1"})
|
|
subscriptions = append(subscriptions, subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: "Category 2"})
|
|
|
|
output := serialize(subscriptions)
|
|
feeds, err := parse(bytes.NewBufferString(output))
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(feeds) != 3 {
|
|
t.Errorf("Wrong number of subscriptions: %d instead of %d", len(feeds), 3)
|
|
}
|
|
|
|
found := false
|
|
for _, feed := range feeds {
|
|
if feed.Title == "Feed 1" && feed.CategoryName == "Category 1" &&
|
|
feed.FeedURL == "http://example.org/feed/1" && feed.SiteURL == "http://example.org/1" {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
t.Error("Serialized feed is incorrect")
|
|
}
|
|
}
|
|
|
|
func TestNormalizedCategoriesOrder(t *testing.T) {
|
|
var orderTests = []struct {
|
|
naturalOrderName string
|
|
correctOrderName string
|
|
}{
|
|
{"Category 2", "Category 1"},
|
|
{"Category 3", "Category 2"},
|
|
{"Category 1", "Category 3"},
|
|
}
|
|
|
|
var subscriptions []subcription
|
|
subscriptions = append(subscriptions, subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: orderTests[0].naturalOrderName})
|
|
subscriptions = append(subscriptions, subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: orderTests[1].naturalOrderName})
|
|
subscriptions = append(subscriptions, subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: orderTests[2].naturalOrderName})
|
|
|
|
feeds := convertSubscriptionsToOPML(subscriptions)
|
|
|
|
for i, o := range orderTests {
|
|
if feeds.Outlines[i].Text != o.correctOrderName {
|
|
t.Fatalf("need %v, got %v", o.correctOrderName, feeds.Outlines[i].Text)
|
|
}
|
|
}
|
|
}
|