本文整理汇总了Golang中github.com/apognu/xml/utils.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestEnclosureBasic
func TestEnclosureBasic(t *testing.T) {
var testdata = []testEnclosure{
{`<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />`,
nil,
NewTestEnclosure("http://www.scripting.com/mp3s/weatherReportSuite.mp3", "12216320", "audio/mpeg"),
},
{`<enclosure length="12216320" type="audio/mpeg" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestEnclosure("", "12216320", "audio/mpeg"),
},
{`<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" type="audio/mpeg" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestEnclosure("http://www.scripting.com/mp3s/weatherReportSuite.mp3", "", "audio/mpeg"),
},
{`<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestEnclosure("http://www.scripting.com/mp3s/weatherReportSuite.mp3", "12216320", ""),
},
}
nbErrors := 0
len := len(testdata)
for _, testenclosure := range testdata {
testcase := _TestEnclosureToTestVisitor(testenclosure)
if err := testcase.CheckTestCase(); err != nil {
t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
nbErrors++
}
}
t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
示例2: validateLinks
func (e *Entry) validateLinks(err *utils.ErrorAggregator) {
combinations := make([]string, 0)
hasAlternateRel := false
for _, link := range e.Links {
if link.Rel.Value == "alternate" {
hasAlternateRel = true
s := link.Type.Value + link.HrefLang.Value
unique := true
for _, comb := range combinations {
if s == comb {
err.NewError(xmlutils.NewError(LinkAlternateDuplicated, fmt.Sprintf("Alternate Link duplicated: hreflang '%s' type '%s'", link.HrefLang.Value, link.Type.Value)))
unique = false
}
}
if unique {
combinations = append(combinations, s)
}
}
}
if e.Occurences.Count("content") == 0 && !hasAlternateRel {
err.NewError(xmlutils.NewError(NoContentOrAlternateLink, "Entry should have either a Content element or a Link with alternate type"))
}
}
示例3: TestDateBasic
func TestDateBasic(t *testing.T) {
var testdata = []testDate{
{`<updated>Tue, 20 Sep 2010 16:02:50 GMT</updated>`,
nil,
NewTestDate("Tue, 20 Sep 2010 16:02:50 GMT"),
},
{`<updated>Tue, 20 Sep 2010 16:02:50</updated>`,
xmlutils.NewError(DateFormat, ""),
NewTestDate("0"),
},
{`<updated>2003-12-13T18:30:02.25</updated>`,
xmlutils.NewError(DateFormat, ""),
NewTestDate("0"),
},
}
nbErrors := 0
len := len(testdata)
for _, testdate := range testdata {
testcase := testDateToTestVisitor(testdate)
if err := testcase.CheckTestCase(); err != nil {
t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
nbErrors++
}
}
t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
示例4: TestIdBasic
func TestIdBasic(t *testing.T) {
var testdata = []testId{
{`<id xml:lang="en-us" xml:base="http://yo.com">https://www.yo.com</id>`,
nil,
IdWithBaseLang(NewTestId("https://www.yo.com"), "en-us", "http://yo.com"),
},
{`<id>https://www.yo.com</id>`,
nil,
NewTestId("https://www.yo.com"),
},
{`<id>https://www.%yo.com</id>`,
xmlutils.NewError(IriNotAbsolute, ""),
NewTestId("https://www.%yo.com"),
},
{`<id>
https://www.%yo.com
</id>`,
xmlutils.NewError(IriNotAbsolute, ""),
NewTestId("https://www.%yo.com"),
},
}
nbErrors := 0
len := len(testdata)
for _, testid := range testdata {
testcase := testIdToTestVisitor(testid)
if err := testcase.CheckTestCase(); err != nil {
t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
nbErrors++
}
}
t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
示例5: ProcessEndElement
func (i *InlineXHTMLContent) ProcessEndElement(el xml.EndElement) (xmlutils.Visitor, xmlutils.ParserError) {
level := i.depth.Up()
if level == xmlutils.RootLevel {
if err := i.EncodeXHTMLToken(el); err != nil {
return i, xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML")
}
if err := i.flush(); err != nil {
return i, err
}
i.completed = true
return i, nil
}
if level == xmlutils.ParentLevel {
if err := i.flush(); err != nil {
return i.Parent, err
}
if i.Parent != nil {
return i.Parent.ProcessEndElement(el)
}
return nil, nil
}
if err := i.EncodeXHTMLToken(el); err != nil {
return i, xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML")
}
return i, nil
}
示例6: validateLinks
func (f *Feed) validateLinks(err *utils.ErrorAggregator) {
combinations := make([]string, 0)
hasSelf := false
for _, link := range f.Links {
if link.Rel.Value == "alternate" {
s := link.Type.Value + link.HrefLang.Value
unique := true
for _, comb := range combinations {
if s == comb {
err.NewError(xmlutils.NewError(LinkAlternateDuplicated, fmt.Sprintf("Alternate Link duplicated: hreflang '%s' type '%s'", link.HrefLang.Value, link.Type.Value)))
unique = false
}
}
if unique {
combinations = append(combinations, s)
}
} else if link.Rel.Value == "self" {
hasSelf = true
}
}
if !hasSelf {
err.NewError(xmlutils.NewError(MissingSelfLink, "Feed must have a link with rel attribute set to 'self'"))
}
}
示例7: TestGeneratorBasic
func TestGeneratorBasic(t *testing.T) {
var testdata = []testGenerator{
{`<generator uri="http://there.com" version="4.0" xml:lang="en-us" xml:base="http://yo.com">my generator</generator>`,
nil,
GeneratorWithBaseLang(NewTestGenerator("4.0", "http://there.com", "my generator"), "en-us", "http://yo.com"),
},
{`<generator uri="http://there.com" version="4.0">my generator</generator>`,
nil,
NewTestGenerator("4.0", "http://there.com", "my generator"),
},
{`<generator uri="http://there.com" version="4.0"><name>CHILD</name></generator>`,
xmlutils.NewError(LeafElementHasChild, ""),
NewTestGenerator("4.0", "http://there.com", "CHILD"),
},
{`<generator uri="http://%there.com" version="4.0">my generator</generator>`,
xmlutils.NewError(IriNotValid, ""),
NewTestGenerator("4.0", "http://%there.com", "my generator"),
},
}
nbErrors := 0
len := len(testdata)
for _, testgenerator := range testdata {
testcase := testGeneratorToTestVisitor(testgenerator)
if err := testcase.CheckTestCase(); err != nil {
t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
nbErrors++
}
}
t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
示例8: Validate
func (u *Updated) Validate() xmlutils.ParserError {
errAgg := utils.NewErrorAggregator()
link, ok := u.Parent.(*atom.Link)
if !ok {
errAgg.NewError(xmlutils.NewError(NotInLinkElement, "updated attr should be placed in link element"))
} else {
if link.Rel.String() != "replies" {
errAgg.NewError(xmlutils.NewError(LinkNotReplies, "link element should avec a 'replies' rel for this extension"))
}
}
return errAgg.ErrorObject()
}
示例9: relIsIANA
func relIsIANA(name, s string) xmlutils.ParserError {
if s == "alternate" || s == "related" || s == "self" || s == "enclosure" || s == "via" {
return nil
}
return xmlutils.NewError(RelNotValid, fmt.Sprintf("rel is not valid: %s", s))
}
示例10: contentTypeIsValid
func contentTypeIsValid(name, s string) xmlutils.ParserError {
if s == "text" || s == "html" || s == "xhtml" {
return xmlutils.NewError(ContentTypeIsNotValid, "type not valid")
}
return nil
}
示例11: ProcessStartElement
func (i *InlineOtherContent) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
err := utils.NewErrorAggregator()
if i.depth.IsRoot() {
for _, attr := range el.Attr {
switch attr.Name.Local {
case "type":
i.Type.Value = attr.Value
i.Type.IncOccurence()
}
}
} else {
if error := i.Encoder.EncodeToken(el); error != nil {
err.NewError(xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML"))
}
if i.depth.Level > 0 {
i.hasChild = true
}
}
i.depth.Down()
return i, nil
}
示例12: TestLogoBasic
func TestLogoBasic(t *testing.T) {
var testdata = []testLogo{
{`<logo xml:lang="en-us" xml:base="http://yo.com">https://www.yo.com</logo>`,
nil,
LogoWithBaseLang(NewTestLogo("https://www.yo.com"), "en-us", "http://yo.com"),
},
{`<logo>https://www.yo.com</logo>`,
nil,
NewTestLogo("https://www.yo.com"),
},
{`<logo>https://www.%yo.com</logo>`,
xmlutils.NewError(IriNotValid, ""),
NewTestLogo("https://www.%yo.com"),
},
}
nbErrors := 0
len := len(testdata)
for _, testlogo := range testdata {
testcase := testLogoToTestVisitor(testlogo)
if err := testcase.CheckTestCase(); err != nil {
t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
nbErrors++
}
}
t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
示例13: ProcessStartElement
func (g *Generator) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
if g.depth.IsRoot() {
g.reset()
for _, attr := range el.Attr {
switch attr.Name.Space {
case xmlutils.XML_NS:
g.ProcessAttr(attr)
case "":
switch attr.Name.Local {
case "uri":
g.Uri.Value = attr.Value
g.Uri.IncOccurence()
case "version":
g.Version.Value = attr.Value
g.Version.IncOccurence()
}
default:
g.Extension.ProcessAttr(attr, g)
}
}
}
if g.depth.Down() == xmlutils.MaxDepthReached {
return g, xmlutils.NewError(LeafElementHasChild, "'generator' shoud not have childs")
}
return g, nil
}
示例14: TestSourceBasic
func TestSourceBasic(t *testing.T) {
var testdata = []testSource{
{`<source>Tomalak's Realm</source>`,
xmlutils.NewError(MissingAttribute, ""),
NewTestSource("", "Tomalak's Realm"),
},
{`<source url="http://www.tomaltak.org/links2.xml">Tomalak's Realm</source>`,
nil,
NewTestSource("http://www.tomaltak.org/links2.xml", "Tomalak's Realm"),
},
}
nbErrors := 0
len := len(testdata)
for _, testsource := range testdata {
testcase := _TestSourceToTestVisitor(testsource)
if err := testcase.CheckTestCase(); err != nil {
t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
nbErrors++
}
}
t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
示例15: flush
func (i *InlineXHTMLContent) flush() xmlutils.ParserError {
err := i.Encoder.Flush()
if err != nil {
return xmlutils.NewError(CannotFlush, "cannot flush XHTML")
}
return nil
}