示例#1
0
func TestParseXmlTestS2(t *testing.T) {
	res := ""
	emitter := func(ed *contentBuffer.EmitterData) bool {
		res = ed.Content
		return false
	}
	reader := bytes.NewReader([]byte("<hello><text xml:space=\"preserve\">this</text><hello2>Test2</hello2><hello3>Test3</hello3></hello>"))
	saxReader := newTestSaxReader(emitter)
	tm := tagMatcher.NewTagMatcher("?xml:space")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, res, "<text xml:space=\"preserve\">this</text>")
}
示例#2
0
func TestParseXmlOneNodeEmptySearch(t *testing.T) {
	res := ""
	emitter := func(ed *contentBuffer.EmitterData) bool {
		res = ed.Content
		return false
	}
	reader := bytes.NewReader([]byte("<hello>test</hello>"))
	saxReader := newTestSaxReader(emitter)
	tm := tagMatcher.NewTagMatcher("")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, res, "")
}
示例#3
0
func TestParseXmlTest(t *testing.T) {
	res := ""
	emitter := func(ed *contentBuffer.EmitterData) bool {
		res = ed.Content
		return false
	}
	reader := bytes.NewReader([]byte("<hello id=\"123\" ref=\"42\"><hello2 idx=\"1234\" refx=\"421\">test</hello2></hello>"))
	saxReader := newTestSaxReader(emitter)
	tm := tagMatcher.NewTagMatcher("hello?id=123&ref=42/hello2?idx=1234&refx=421")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, res, "<hello2 idx=\"1234\" refx=\"421\">test</hello2>")
}
示例#4
0
func TestParseXmlOneNodeTwoAttributesNoMatch(t *testing.T) {
	res := ""
	emitter := func(ed *contentBuffer.EmitterData) bool {
		res = ed.Content
		return false
	}
	reader := bytes.NewReader([]byte("<hello id=\"123\" ref=\"42\">test</hello>"))
	saxReader := newTestSaxReader(emitter)
	tm := tagMatcher.NewTagMatcher("hello?id=123&ref=421")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.NotEqual(t, res, "<hello id=\"123\" ref=\"42\">test</hello>")
}
示例#5
0
func TestParseXmlOneNodeOneAttributeSingle(t *testing.T) {
	res := ""
	emitter := func(ed *contentBuffer.EmitterData) bool {
		res = ed.Content
		return false
	}
	reader := bytes.NewReader([]byte("<hello id='123'>test</hello>"))
	saxReader := newTestSaxReader(emitter)
	tm := tagMatcher.NewTagMatcher("hello?id=123")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, res, "<hello id='123'>test</hello>")
}
示例#6
0
func TestParseXmlNodesWithLtEscapeTag(t *testing.T) {
	res := ""
	emitter := func(ed *contentBuffer.EmitterData) bool {
		res = ed.Content
		return false
	}
	reader := bytes.NewReader([]byte("<helloA><helloB>&lt;helloC>&lt;/helloC></helloB></helloA>"))
	saxReader := newTestSaxReader(emitter)
	tm := tagMatcher.NewTagMatcher("helloA/helloB")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, res, "<helloB>&lt;helloC>&lt;/helloC></helloB>")
}
示例#7
0
func TestParseXmlNodeConstrainedBuffer(t *testing.T) {
	res := ""
	emitter := func(ed *contentBuffer.EmitterData) bool {
		res = ed.Content
		return false
	}
	reader := bytes.NewReader([]byte("<hello>test</hello>"))
	saxReader := newTestSaxReader(emitter)
	saxReader.ReaderBufferSize = 1
	tm := tagMatcher.NewTagMatcher("hello")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, res, "<hello>test</hello>")
}
示例#8
0
func TestParseXmlNodesWithCdataAndComment(t *testing.T) {
	var actuals []string = make([]string, 10)
	var actualsPos int = 0
	emitter := func(ed *contentBuffer.EmitterData) bool {
		actuals[actualsPos] = ed.Content
		actualsPos++
		return false
	}
	reader := bytes.NewReader([]byte("<helloA><!-- test<>--<><--><helloB><helloC><![CDATA[Hello<! World!]]></helloC><helloC>C2</helloC></helloB></helloA>"))
	saxReader := newTestSaxReader(emitter)
	tm := tagMatcher.NewTagMatcher("helloA/helloB/helloC")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, actuals[0], "<helloC><![CDATA[Hello<! World!]]></helloC>")
	assert.Equal(t, actuals[1], "<helloC>C2</helloC>")
}
示例#9
0
func TestParseXmlNodesConstrainedBuffer(t *testing.T) {
	var actuals []string = make([]string, 10)
	var actualsPos int = 0
	emitter := func(ed *contentBuffer.EmitterData) bool {
		actuals[actualsPos] = ed.Content
		actualsPos++
		return false
	}
	reader := bytes.NewReader([]byte("<helloA><helloB><helloC>C1</helloC><helloC>C2</helloC></helloB></helloA>"))
	saxReader := newTestSaxReader(emitter)
	saxReader.ReaderBufferSize = 1
	tm := tagMatcher.NewTagMatcher("helloA/helloB/helloC")
	err := saxReader.Read(reader, &tm)
	assert.Nil(t, err)
	assert.Equal(t, actuals[0], "<helloC>C1</helloC>")
	assert.Equal(t, actuals[1], "<helloC>C2</helloC>")
}