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) {
have, _ := ParseAtom(strings.NewReader(`
have, _ := Parse(strings.NewReader(`
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>

View File

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

View File

@ -6,7 +6,7 @@ func TestSniff(t *testing.T) {
testcases := [][2]string{
{
`<?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>`,

View File

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

View File

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

View File

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