Ejemplo n.º 1
0
func (s *BasicSuite) TestHTML(c *C) {
	node, err := xmlpath.ParseHTML(bytes.NewBuffer(trivialHtml))
	c.Assert(err, IsNil)
	path := xmlpath.MustCompile("/root/foo")
	result, ok := path.String(node)
	c.Assert(ok, Equals, true)
	c.Assert(result, Equals, "<a>")
}
Ejemplo n.º 2
0
func (s *BasicSuite) TestRootText(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(trivialXml))
	c.Assert(err, IsNil)
	path := xmlpath.MustCompile("/")
	result, ok := path.String(node)
	c.Assert(ok, Equals, true)
	c.Assert(result, Equals, "abcdefg")
}
Ejemplo n.º 3
0
func (s *BasicSuite) BenchmarkSimplePathExists(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(instancesXml))
	c.Assert(err, IsNil)
	path := xmlpath.MustCompile("/DescribeInstancesResponse/reservationSet/item/instancesSet/item/instanceType")
	var exists bool
	c.ResetTimer()
	for i := 0; i < c.N; i++ {
		exists = path.Exists(node)
	}
	c.StopTimer()
	c.Assert(exists, Equals, true)
}
Ejemplo n.º 4
0
func (s *BasicSuite) BenchmarkSimplePathString(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(instancesXml))
	c.Assert(err, IsNil)
	path := xmlpath.MustCompile("/DescribeInstancesResponse/reservationSet/item/instancesSet/item/instanceType")
	var str string
	c.ResetTimer()
	for i := 0; i < c.N; i++ {
		str, _ = path.String(node)
	}
	c.StopTimer()
	c.Assert(str, Equals, "m1.small")
}