Exemplo n.º 1
0
func (s *BasicSuite) BenchmarkSimplePathCompile(c *C) {
	var err error
	c.ResetTimer()
	for i := 0; i < c.N; i++ {
		_, err = xmlpath.Compile("/DescribeInstancesResponse/reservationSet/item/groupSet/item/groupId")
	}
	c.StopTimer()
	c.Assert(err, IsNil)
}
Exemplo n.º 2
0
func (s *BasicSuite) TestLibraryTable(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(libraryXml))
	c.Assert(err, IsNil)
	for _, test := range libraryTable {
		cmt := Commentf("xml path: %s", test.path)
		path, err := xmlpath.Compile(test.path)
		if want, ok := test.result.(cerror); ok {
			c.Assert(err, ErrorMatches, string(want), cmt)
			c.Assert(path, IsNil, cmt)
			continue
		}
		c.Assert(err, IsNil)
		switch want := test.result.(type) {
		case string:
			got, ok := path.String(node)
			c.Assert(ok, Equals, true, cmt)
			c.Assert(got, Equals, want, cmt)
			c.Assert(path.Exists(node), Equals, true, cmt)
			iter := path.Iter(node)
			iter.Next()
			node := iter.Node()
			c.Assert(node.String(), Equals, want, cmt)
			c.Assert(string(node.Bytes()), Equals, want, cmt)
		case []string:
			var alls []string
			var allb []string
			iter := path.Iter(node)
			for iter.Next() {
				alls = append(alls, iter.Node().String())
				allb = append(allb, string(iter.Node().Bytes()))
			}
			c.Assert(alls, DeepEquals, want, cmt)
			c.Assert(allb, DeepEquals, want, cmt)
			s, sok := path.String(node)
			b, bok := path.Bytes(node)
			if len(want) == 0 {
				c.Assert(sok, Equals, false, cmt)
				c.Assert(bok, Equals, false, cmt)
				c.Assert(s, Equals, "")
				c.Assert(b, IsNil)
			} else {
				c.Assert(sok, Equals, true, cmt)
				c.Assert(bok, Equals, true, cmt)
				c.Assert(s, Equals, alls[0], cmt)
				c.Assert(string(b), Equals, alls[0], cmt)
				c.Assert(path.Exists(node), Equals, true, cmt)
			}
		case exists:
			wantb := bool(want)
			ok := path.Exists(node)
			c.Assert(ok, Equals, wantb, cmt)
			_, ok = path.String(node)
			c.Assert(ok, Equals, wantb, cmt)
		}
	}
}