Return pointer instead of object

(Tests correction will come in a next commit)
This commit is contained in:
Nicolas Wavrant 2019-03-23 23:05:10 +09:00
parent 7d465cb032
commit f8e57ec956
2 changed files with 13 additions and 10 deletions

View File

@ -11,7 +11,7 @@ import (
// --------------------------------------------------
type RSSFeed struct {
XMLName xml.Name `xml:"rss"`
Channel Channel
Channel *Channel
}
type Channel struct {
@ -105,7 +105,7 @@ type Category struct {
// --------------------------------------------------
// Library Functions
// --------------------------------------------------
func Parse(xml_content []byte) (Channel, error) {
func Parse(xml_content []byte) (*Channel, error) {
var feed RSSFeed
xml.Unmarshal(xml_content, &feed)
return feed.Channel, nil

View File

@ -2,7 +2,6 @@ package rssreader
import (
"io/ioutil"
"reflect"
"testing"
)
@ -24,13 +23,17 @@ func TestParse(t *testing.T) {
"Link": "http://www.lemonde.fr/rss/une.xml",
}
for property, value := range result_dict {
r := reflect.ValueOf(rss)
channel_value := reflect.Indirect(r).FieldByName(property)
if string(channel_value.String()) != value {
t.Fail()
}
if rss.Title != result_dict["Title"] {
t.Fail()
}
if rss.Description != result_dict["Description"] {
t.Fail()
}
if rss.Copyright != result_dict["Copyright"] {
t.Fail()
}
if rss.Link != result_dict["Link"] {
t.Fail()
}
if len(rss.Items) != 21 {