mbklein / equivalent-xml

Easy equivalency tests for Nokogiri and Oga XML
MIT License
94 stars 29 forks source link

Compare over more node with the same name: #11

Closed Lexanius closed 11 years ago

Lexanius commented 11 years ago

the following nodes, will be wrong compare:

text_1 = '<?xml version="1.0"?>
<info>
<entry
   kind="dir"
   path="."
   revision="29">
<url>file:///home/user/svnrep/svnserver</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>23296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="29">
<author>user</author>
<date>2013-03-15T12:20:26.098031Z</date>
</commit>
</entry>

<entry
   kind="dir"
   path="Projekt"
   revision="28">
<url>file:///home/user/svnrep/svnserver/Projekt</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>423296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="28">
<author>user</author>
<gooo a="4" b="2">
<date>2013-03-08T15:19:56.178552Z</date>
</commit>

</entry>
<entry
   kind="dir"
   path="./"
   revision="29">
<url>file:///home/user/svnrep/svnserver</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>23296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="29">
<author>user</author>
<date>2013-03-15T12:20:26.098031Z</date>
</commit>
</entry> 

<entry
   kind="dir"
   path="Projekt"
   revision="1">
<url>file:///home/user/svnrep/svnserver/Projekt</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>423296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="28">
<author>user</author>
<gooo a="4" b="2">
<date>2013-03-08T15:19:56.178552Z</date>
</commit>
</entry>
</info>
'
node_1 = Nokogiri::XML(text_1)
text_2 = '<?xml version="1.0"?>
<info>
<entry
   kind="dir"
   path="./"
   revision="29">
<url>file:///home/user/svnrep/svnserver</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>23296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="29">
<author>user</author>
<date>2013-03-15T12:20:26.098031Z</date>
</commit>
</entry>

<entry
   kind="dir"
   path="Projekt"
   revision="28">
<url>file:///home/user/svnrep/svnserver/Projekt</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>423296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="28">
<author>user</author>
<gooo a="4" b="2">
<date>2013-03-08T15:19:56.178552Z</date>
</commit>
</entry>

<entry
   kind="dir"
   path="."
   revision="29">
<url>file:///home/user/svnrep/svnserver</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>23296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="29">
<author>user</author>
<date>2013-03-15T12:20:26.098031Z</date>
</commit>
</entry> 

<entry
   kind="dir"
   path="Projekt"
   revision="1">
<url>file:///home/user/svnrep/svnserver/Projekt</url>
<repository>
<root>file:///home/user/svnrep/svnserver</root>
<uuid>423296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="28">
<author>user</author>
<gooo a="4" b="2">
<date>2013-03-08T15:19:56.178552Z</date>
</commit>
</entry>
</info>
'

with the options: :element_order => false, :normalize_whitespace => true

but with a diff these are the same:

@@ -3 +3 @@
-<entry kind="dir" path="." revision="29">
+<entry kind="dir" path="./" revision="29">
@@ -19 +18,0 @@
-
@@ -35,2 +33,0 @@
-
-
@@ -38 +35,2 @@
-<entry kind="dir" path="./" revision="29">
+
+<entry kind="dir" path="." revision="29">
@@ -54 +51,0 @@
-

After my search: The algorithm get in the second compare (compare_nodesets) a wrong input:

NODESETS (Infomation shorted for visibility)

 <url>file:///home/user/svnrep/svnserver</url><repository><root>file:///home/user/svnrep/svnserver</root><uuid>23296ed4-733e-4fb8-a59a-8fb1a468b90c</uuid></repository><wc-info><schedule>normal</schedule><
depth>infinity</depth></wc-info><commit revision="29"><author>user</author><date>2013-03-15T12:20:26.098031Z</date></commit>

in nodeset_1 and

 <url>file:///home/user/svnrep/svnserver/Projekt</url><repository><root>file:///home/user/svnrep/svnserver
        <entry kind="dir" path="." revision="29"><url>file:///home/user/svnrep/svnserver</url><repository><root>file:///home/user/svnrep/svnserver
        <entry kind="dir" path="Projekt" revision="1"><url>file:///home/user/svnrep/svnserver/Projekt</url><repository><root>file:///home/user/svnrep/svnserver

in nodeset_2 and so the algorithm return false, because the wrong length

Use: ruby 1.8.7 OS Linux Version: official ruby gem version and current (date:25.03.13)

Lexanius commented 11 years ago

i found the problem: me-.- sorry, but after searching a long time, i thinking i have found a bug... but it wasent so. Nice work!!