本文整理汇总了Golang中github.com/apognu/xml/utils.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:apognu,项目名称:xml,代码行数:34,代码来源:enclosure_test.go
示例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"))
}
}
开发者ID:apognu,项目名称:xml,代码行数:27,代码来源:entry.go
示例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)
}
开发者ID:apognu,项目名称:xml,代码行数:29,代码来源:date_test.go
示例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)
}
开发者ID:apognu,项目名称:xml,代码行数:35,代码来源:id_test.go
示例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
}
开发者ID:apognu,项目名称:xml,代码行数:34,代码来源:inlineXHTMLcontent.go
示例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'"))
}
}
开发者ID:apognu,项目名称:xml,代码行数:28,代码来源:feed.go
示例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)
}
开发者ID:apognu,项目名称:xml,代码行数:33,代码来源:generator_test.go
示例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()
}
开发者ID:apognu,项目名称:xml,代码行数:14,代码来源:link.go
示例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))
}
开发者ID:apognu,项目名称:xml,代码行数:7,代码来源:validator.go
示例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
}
开发者ID:apognu,项目名称:xml,代码行数:7,代码来源:validator.go
示例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
}
开发者ID:apognu,项目名称:xml,代码行数:26,代码来源:inlineothercontent.go
示例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)
}
开发者ID:apognu,项目名称:xml,代码行数:29,代码来源:logo_test.go
示例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
}
开发者ID:apognu,项目名称:xml,代码行数:31,代码来源:generator.go
示例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)
}
开发者ID:apognu,项目名称:xml,代码行数:26,代码来源:source_test.go
示例15: flush
func (i *InlineXHTMLContent) flush() xmlutils.ParserError {
err := i.Encoder.Flush()
if err != nil {
return xmlutils.NewError(CannotFlush, "cannot flush XHTML")
}
return nil
}
开发者ID:apognu,项目名称:xml,代码行数:8,代码来源:inlineXHTMLcontent.go
示例16: ProcessCharData
func (i *InlineXHTMLContent) ProcessCharData(el xml.CharData) (xmlutils.Visitor, xmlutils.ParserError) {
if len(strings.Fields(string(el))) > 0 {
if err := i.flush(); err != nil {
return i, err
}
if _, err := i.Content.Write(el); err != nil {
return i, xmlutils.NewError(CannotFlush, "cannot flush content")
}
if i.depth.Level == 0 {
return i, xmlutils.NewError(XHTMLRootNodeNotDiv, "XHTML element should have a root")
}
}
return i, nil
}
开发者ID:apognu,项目名称:xml,代码行数:17,代码来源:inlineXHTMLcontent.go
示例17: TestDateBasic
func TestDateBasic(t *testing.T) {
var testdata = []testDate{
{`<updated xml:lang="en-us" xml:base="http://yo.com">2003-12-13T18:30:02Z</updated>`,
nil,
DateWithBaseLang(NewTestDate("2003-12-13T18:30:02Z"), "en-us", "http://yo.com"),
},
{`<updated>2003-12-13T18:30:02Z</updated>`,
nil,
NewTestDate("2003-12-13T18:30:02Z"),
},
{`<updated>2003-12-13T18:30:02.25Z</updated>`,
nil,
NewTestDate("2003-12-13T18:30:02.25Z"),
},
{`<updated>2003-12-13T18:30:02+01:00</updated>`,
nil,
NewTestDate("2003-12-13T18:30:02+01:00"),
},
{`<updated>2003-12-13T18:30:02.25+01:00</updated>`,
nil,
NewTestDate("2003-12-13T18:30:02.25+01:00"),
},
{`<updated>2003-12-13t18:30:02z</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)
}
开发者ID:apognu,项目名称:xml,代码行数:45,代码来源:dateconstruct_test.go
示例18: ProcessCharData
func (d *Date) ProcessCharData(el xml.CharData) (xmlutils.Visitor, xmlutils.ParserError) {
var err error
d.Time, err = time.Parse(time.RFC3339, string(el))
if err != nil || d.Time.IsZero() {
return d, xmlutils.NewError(DateFormat, fmt.Sprintf("date not well formatted '%v'", string(el)))
}
return d, nil
}
开发者ID:apognu,项目名称:xml,代码行数:9,代码来源:dateconstruct.go
示例19: TestCloudBasic
func TestCloudBasic(t *testing.T) {
var testdata = []testCloud{
{`<cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="myCloud.rssPleaseNotify" protocol="xml-rpc" />`,
nil,
NewTestCloud("rpc.sys.com", "80", "/RPC2", "myCloud.rssPleaseNotify", "xml-rpc"),
},
{`<cloud port="80" path="/RPC2" registerProcedure="myCloud.rssPleaseNotify" protocol="xml-rpc" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestCloud("", "80", "/RPC2", "myCloud.rssPleaseNotify", "xml-rpc"),
},
{`<cloud domain="rpc.sys.com" path="/RPC2" registerProcedure="myCloud.rssPleaseNotify" protocol="xml-rpc" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestCloud("rpc.sys.com", "", "/RPC2", "myCloud.rssPleaseNotify", "xml-rpc"),
},
{`<cloud domain="rpc.sys.com" port="80" registerProcedure="myCloud.rssPleaseNotify" protocol="xml-rpc" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestCloud("rpc.sys.com", "80", "", "myCloud.rssPleaseNotify", "xml-rpc"),
},
{`<cloud domain="rpc.sys.com" port="80" path="/RPC2" protocol="xml-rpc" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestCloud("rpc.sys.com", "80", "/RPC2", "", "xml-rpc"),
},
{`<cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="myCloud.rssPleaseNotify" />`,
xmlutils.NewError(MissingAttribute, ""),
NewTestCloud("rpc.sys.com", "80", "/RPC2", "myCloud.rssPleaseNotify", ""),
},
}
nbErrors := 0
len := len(testdata)
for _, testcloud := range testdata {
testcase := _TestCloudToTestVisitor(testcloud)
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)
}
开发者ID:apognu,项目名称:xml,代码行数:42,代码来源:cloud_test.go
示例20: ProcessStartElement
func (i *InlineXHTMLContent) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
err := utils.NewErrorAggregator()
if i.depth.Level == 0 && el.Name.Local != "div" {
err.NewError(xmlutils.NewError(XHTMLRootNodeNotDiv, "Inline XHTML root node must be a div"))
}
if i.completed == true {
err.NewError(xmlutils.NewError(NotUniqueChild, "Inline XHTML should be contained in a unique node"))
}
i.depth.Down()
if error := i.CheckXHTMLSpace(el); error != nil {
err.NewError(error)
}
if error := i.EncodeXHTMLToken(el); error != nil {
err.NewError(xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML"))
}
return i, err.ErrorObject()
}
开发者ID:apognu,项目名称:xml,代码行数:20,代码来源:inlineXHTMLcontent.go
注:本文中的github.com/apognu/xml/utils.NewError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论