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>") }
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") }
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) }
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") }