Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed 890a9fc

Fixed a regression bug, and corrected the ID algorithm that could have
been problematic on nested tags.

  • Participants
  • Parent commits 07bd88e

Comments (0)

Files changed (3)

File perl/modules/XML-SemanaticDiff/MANIFEST

 Changes
+eg/camelids2.xml
+eg/camelids.xml
+eg/xmlsemdiff
+lib/XML/SemanticDiff/BasicHandler.pm
+lib/XML/SemanticDiff.pm
 Makefile.PL
 MANIFEST
-lib/XML/SemanticDiff.pm
-lib/XML/SemanticDiff/BasicHandler.pm
-eg/xmlsemdiff
-eg/camelids.xml
-eg/camelids2.xml
+META.yml                                 Module meta-data (added by MakeMaker)
 t/01basic.t
 t/02load_xml.t
 t/03simple_compare.t
 t/06pass_to_handler.t
 t/07pitest.t
 t/08nonexist_ns.t
-META.yml                                 Module meta-data (added by MakeMaker)
+t/09two-tags.t

File perl/modules/XML-SemanaticDiff/lib/XML/SemanticDiff.pm

         if (defined $to_doc->{$element}) {
 
             # element value test
+            print $element, "\n";
             unless ($from_doc->{$element}->{TextChecksum} eq $to_doc->{$element}->{TextChecksum}) {
                 push (@warnings, $handler->element_value($element, 
                                                          $to_doc->{$element}, 
 my $doc = {};
 my $opts = {};
 
+my $xml_context = [];
+
 sub StartTag {
     my ($expat, $element) = @_;
+
+
     my %attrs = %_;
             
     my @context = $expat->context;
     my $context_length = scalar (@context);
     my $parent = $context[$context_length -1];
     push (@{$descendents->{$parent}}, $element) if $parent;
-    $position_index->{"$element"}++;
+
+    push @{$xml_context}, 
+        {
+            element => "$element", 
+            'index' => ++$position_index->{"$element"},
+        };
+
     my $test_context;
  
+=begin Discard
+
+
     if (@context){
         $test_context = '/' . join ('/', map { $_ . '[' . $position_index->{$_} . ']' } @context);
     }   
         
     $test_context .= '/' . $element . '[' . $position_index->{$element} . ']';
+=end
+
+=cut
+
+    $test_context = _calc_test_context();
 
     $doc->{"$test_context"}->{NamespaceURI} = $expat->namespace($element) || "";
     $doc->{"$test_context"}->{Attributes}   = \%attrs || {};
 
 }
 
+sub _calc_test_context
+{
+    return "/" . join("/", map { $_->{'element'} . "[" . $_->{'index'} . "]" } @$xml_context);
+}
+
 sub EndTag {
     my ($expat, $element) = @_;
     
-    
     my @context = $expat->context;
-    my $test_context;
-            
+
+=begin Discard
+
+
     if (@context){
         $test_context = '/' . join ('/', map { $_ . '[' . $position_index->{$_} . ']' } @context);
     }
          
     $test_context .= '/' . $element . '[' . $position_index->{$element} . ']';
-            
+
+=end
+
+=cut
+
+    my $test_context = _calc_test_context();
+
     my $text;
     if ( defined( $char_accumulator->{$element} )) { 
         $text = $char_accumulator->{$element};
     
     $doc->{"$test_context"}->{TagEnd} = $expat->current_line if $opts->{keeplinenums};
 
-    $position_index->{$element}--;        
+    pop(@$xml_context);
 }
 
 sub Text {
     $descendents = {};
     $position_index = {};
     $char_accumulator = {};
-    $opts = $expat->{'Non-Expat-Options'}
+    $opts = $expat->{'Non-Expat-Options'};
+    $xml_context = [];
 }
         
 sub EndDocument {

File perl/modules/XML-SemanaticDiff/t/09two-tags.t

+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use XML::SemanticDiff;
+
+my $first_item_is_t = <<"EOF";
+<s>
+    <p>
+        T
+    </p>
+    <p>
+        G
+    </p>
+</s>
+EOF
+
+my $first_item_is_f = <<"EOF";
+<s>
+    <p>
+        F
+    </p>
+    <p>
+        G
+    </p>
+</s>
+EOF
+
+my $diff = XML::SemanticDiff->new();
+
+my @results = $diff->compare($first_item_is_t, $first_item_is_f);
+
+# TEST
+is (scalar(@results), 1, "Making sure there's one difference in the XML");
+
+1;
+
+