diff options
author | Brett Vickers <brett@beevik.com> | 2018-04-21 09:24:56 -0700 |
---|---|---|
committer | Brett Vickers <brett@beevik.com> | 2018-04-21 09:24:56 -0700 |
commit | 0b2ce04cd25cb5f5d4389bde81f01c48c1f40bdb (patch) | |
tree | 95deb060f0e527e622d9c4db99d1fc7ca9741a7f | |
parent | 6a151fb14cf7ab22fa536272691b536f0c4e3469 (diff) | |
download | go-etree-0b2ce04cd25cb5f5d4389bde81f01c48c1f40bdb.tar.gz |
fix bug in GetRelativePath.
-rw-r--r-- | etree.go | 2 | ||||
-rw-r--r-- | etree_test.go | 26 |
2 files changed, 14 insertions, 14 deletions
@@ -188,7 +188,7 @@ func (e *Element) GetRelativePath(source *Element) string { findPathIndex := func(e *Element, path []*Element) int { for i, ee := range path { - if e.Tag == ee.Tag { + if e == ee { return i } } diff --git a/etree_test.go b/etree_test.go index e20d28b..ede26d3 100644 --- a/etree_test.go +++ b/etree_test.go @@ -258,18 +258,17 @@ func TestCopy(t *testing.T) { func TestGetPath(t *testing.T) { testdoc := `<a> - <b1> - <c1> - <d1> - </d1> - </c1> - </b1> - <b2> - <c2> - <d2> - </d2> - </c2> - </b2> + <b1> + <c1> + <d1/> + <d1a/> + </c1> + </b1> + <b2> + <c2> + <d2/> + </c2> + </b2> </a>` doc := NewDocument() @@ -302,6 +301,7 @@ func TestGetPath(t *testing.T) { {"a/b2", "a/b1", "../b1", "/a/b1"}, {"a/b1/c1/d1", "a/b2/c2/d2", "../../../b2/c2/d2", "/a/b2/c2/d2"}, {"a/b2/c2/d2", "a/b1/c1/d1", "../../../b1/c1/d1", "/a/b1/c1/d1"}, + {"a/b1/c1/d1", "a/b1/c1/d1a", "../d1a", "/a/b1/c1/d1a"}, } for _, c := range cases { @@ -315,7 +315,7 @@ func TestGetPath(t *testing.T) { p := te.GetPath() if p != c.topath { - t.Errorf("GetPath for '%s'. Expected '/%s', got '%s'.\n", c.to, c.topath, p) + t.Errorf("GetPath for '%s'. Expected '%s', got '%s'.\n", c.to, c.topath, p) } } } |