This commit is contained in:
Nazar Kanaev 2021-03-22 21:25:25 +00:00
parent 7ca9415322
commit 9e8837b37d
6 changed files with 9 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import (
) )
func TestAtom(t *testing.T) { func TestAtom(t *testing.T) {
have, _ := ParseAtom(strings.NewReader(` have, _ := Parse(strings.NewReader(`
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"> <feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title> <title>Example Feed</title>

View File

@ -28,7 +28,7 @@ func sniff(lookup string) (string, processor) {
case "rss": case "rss":
return "rss", ParseRSS return "rss", ParseRSS
case "RDF": case "RDF":
return "rss", ParseRDF return "rdf", ParseRDF
case "feed": case "feed":
return "atom", ParseAtom return "atom", ParseAtom
} }
@ -41,11 +41,9 @@ func sniff(lookup string) (string, processor) {
} }
func Parse(r io.Reader) (*Feed, error) { func Parse(r io.Reader) (*Feed, error) {
chunk := make([]byte, 64) chunk := make([]byte, 1024)
numread, err := r.Read(chunk) if _, err := r.Read(chunk); err != nil {
fmt.Println(numread, err) return nil, fmt.Errorf("Failed to read input: %s", err)
if err != nil {
return nil, fmt.Errorf("Failed to read: %s", err)
} }
_, callback := sniff(string(chunk)) _, callback := sniff(string(chunk))

View File

@ -6,7 +6,7 @@ func TestSniff(t *testing.T) {
testcases := [][2]string{ testcases := [][2]string{
{ {
`<?xml version="1.0"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>`, `<?xml version="1.0"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>`,
"rss", "rdf",
}, },
{ {
`<?xml version="1.0"?><rss version="2.0"><channel></channel></rss>`, `<?xml version="1.0"?><rss version="2.0"><channel></channel></rss>`,

View File

@ -7,7 +7,7 @@ import (
) )
func TestJSONFeed(t *testing.T) { func TestJSONFeed(t *testing.T) {
have, _ := ParseJSON(strings.NewReader(`{ have, _ := Parse(strings.NewReader(`{
"version": "https://jsonfeed.org/version/1", "version": "https://jsonfeed.org/version/1",
"title": "My Example Feed", "title": "My Example Feed",
"home_page_url": "https://example.org/", "home_page_url": "https://example.org/",

View File

@ -7,7 +7,7 @@ import (
) )
func TestRDFFeed(t *testing.T) { func TestRDFFeed(t *testing.T) {
have, _ := ParseRDF(strings.NewReader(`<?xml version="1.0"?> have, _ := Parse(strings.NewReader(`<?xml version="1.0"?>
<rdf:RDF <rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://channel.netscape.com/rdf/simple/0.9/"> xmlns="http://channel.netscape.com/rdf/simple/0.9/">

View File

@ -7,7 +7,7 @@ import (
) )
func TestRSSFeed(t *testing.T) { func TestRSSFeed(t *testing.T) {
have, _ := ParseRSS(strings.NewReader(` have, _ := Parse(strings.NewReader(`
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE rss SYSTEM "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <!DOCTYPE rss SYSTEM "http://my.netscape.com/publish/formats/rss-0.91.dtd">
<rss version="0.91"> <rss version="0.91">