public void TestAbsoluteAndRelativePaths() { var s = TestHelper.ParseString("(node {attr (node 1)} [3.7 (subnode 4) (node 2)])"); var n = s as Node; var matches = s.Find("/node"); Assert.AreEqual(1, matches.Count); Assert.AreEqual(s, matches[0].Value); TestHelper.AssertNodeAndFirstNumberLiteralChild(n, "node", 1, 3, 3, 7); matches = s.Find("node"); Assert.AreEqual(3, matches.Count); Assert.AreEqual(s, matches[0].Value); Assert.AreEqual(n.Children[2] as Node, matches[1].Value); Assert.AreEqual(n.Attributes["attr"] as Node, matches[2].Value); Assert.AreEqual("/node/node#2", matches[1].Path); Assert.AreEqual(matches[0], matches[1].Parent); TestHelper.AssertNodeAndFirstNumberLiteralChild(matches[1].Value as Node, "node", 0, 1, 2, 0); Assert.AreEqual("/node/@attr", matches[2].Path); Assert.AreEqual(matches[0], matches[2].Parent); TestHelper.AssertNodeAndFirstNumberLiteralChild(matches[2].Value as Node, "node", 0, 1, 1, 0); matches = s.Find("/node/@attr"); Assert.AreEqual(1, matches.Count); Assert.AreEqual(n.Attributes["attr"] as Node, matches[0].Value); matches = s.Find("node/^number"); Assert.AreEqual(3, matches.Count); Assert.AreEqual("/node/#0", matches[0].Path); TestHelper.AssertNumberLiteral(matches[0].Value as NumberLiteral, 3, 7); Assert.AreEqual("/node/node#2/#0", matches[1].Path); TestHelper.AssertNumberLiteral(matches[1].Value as NumberLiteral, 2, 0); Assert.AreEqual("/node/@attr/#0", matches[2].Path); TestHelper.AssertNumberLiteral(matches[2].Value as NumberLiteral, 1, 0); matches = s.Find("node/#1"); Assert.AreEqual(1, matches.Count); Assert.AreEqual("/node/subnode#1", matches[0].Path); TestHelper.AssertNodeAndFirstNumberLiteralChild(matches[0].Value as Node, "subnode", 0, 1, 4, 0); matches = s.Find("^node"); Assert.AreEqual(4, matches.Count); matches = s.Find("[has_child(subnode)]"); Assert.AreEqual(1, matches.Count); Assert.AreEqual(s, matches[0].Value); matches = s.Find("[has_attr(attr)]"); Assert.AreEqual(1, matches.Count); Assert.AreEqual(s, matches[0].Value); }