mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Add test case to check different feed encoding and HTTP headers
This commit is contained in:
parent
054fc8ef99
commit
7d1b471d88
6 changed files with 1508 additions and 0 deletions
|
@ -5,7 +5,11 @@
|
|||
package parser // import "miniflux.app/reader/parser"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"miniflux.app/http/client"
|
||||
)
|
||||
|
||||
func TestParseAtom(t *testing.T) {
|
||||
|
@ -150,3 +154,47 @@ func TestParseEmptyFeed(t *testing.T) {
|
|||
t.Error("ParseFeed must returns an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDifferentEncodingWithResponse(t *testing.T) {
|
||||
var unicodeTestCases = []struct {
|
||||
filename, contentType string
|
||||
index int
|
||||
title string
|
||||
}{
|
||||
// Arabic language encoded in UTF-8.
|
||||
{"urdu_UTF8.xml", "text/xml; charset=utf-8", 0, "امریکی عسکری امداد کی بندش کی وجوہات: انڈیا سے جنگ، جوہری پروگرام اور اب دہشت گردوں کی پشت پناہی"},
|
||||
|
||||
// Windows-1251 encoding and not charset in HTTP header.
|
||||
{"encoding_WINDOWS-1251.xml", "text/xml", 0, "Цитата #17703"},
|
||||
|
||||
// No encoding in XML, but defined in HTTP Content-Type header.
|
||||
{"no_encoding_ISO-8859-1.xml", "application/xml; charset=ISO-8859-1", 2, "La criminalité liée surtout à... l'ennui ?"},
|
||||
|
||||
// ISO-8859-1 encoding defined in XML and HTTP header.
|
||||
{"encoding_ISO-8859-1.xml", "application/rss+xml; charset=ISO-8859-1", 5, "Projekt Jedi: Microsoft will weiter mit US-Militär zusammenarbeiten"},
|
||||
|
||||
// UTF-8 encoding defined in RDF document and HTTP header.
|
||||
{"rdf_UTF8.xml", "application/rss+xml; charset=utf-8", 1, "Mega-Deal: IBM übernimmt Red Hat"},
|
||||
|
||||
// UTF-8 encoding defined only in RDF document.
|
||||
{"rdf_UTF8.xml", "application/rss+xml", 1, "Mega-Deal: IBM übernimmt Red Hat"},
|
||||
}
|
||||
|
||||
for _, tc := range unicodeTestCases {
|
||||
content, err := ioutil.ReadFile("testdata/" + tc.filename)
|
||||
if err != nil {
|
||||
t.Fatalf(`Unable to read file %q: %v`, tc.filename, err)
|
||||
}
|
||||
|
||||
r := &client.Response{Body: bytes.NewReader(content), ContentType: tc.contentType}
|
||||
r.EnsureUnicodeBody()
|
||||
feed, parseErr := ParseFeed(r.String())
|
||||
if parseErr != nil {
|
||||
t.Errorf(`Parsing error for %q - %q: %v`, tc.filename, tc.contentType, parseErr)
|
||||
}
|
||||
|
||||
if feed.Entries[tc.index].Title != tc.title {
|
||||
t.Errorf(`Unexpected title, got %q instead of %q`, feed.Entries[tc.index].Title, tc.title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue