Commits

Daniel Frett  committed c68551d

add support for calling normalize on a Document node.

also updated normalize method return value to follow the DOM level 2 spec.

  • Participants
  • Parent commits ad5dc8a

Comments (0)

Files changed (3)

         RETVAL
 
 
-int
+void
 normalize( self )
         xmlNodePtr self
     CODE:
-        RETVAL = domNodeNormalize( self );
-    OUTPUT:
-        RETVAL
+        domNodeNormalize( self );
 
 
 SV*
     case XML_ELEMENT_NODE:
         domNodeNormalizeList( (xmlNodePtr) node->properties );
     case XML_ATTRIBUTE_NODE:
+    case XML_DOCUMENT_NODE:
         return( domNodeNormalizeList( node->children ) );
         break;
     default:

File t/06elements.t

 use warnings;
 
 # Should be 187.
-use Test::More tests => 187;
+use Test::More tests => 191;
 
 use XML::LibXML;
 
 }
 
 # 4. Text Append and Normalization
-
+# 4.1 Normalization on an Element node
 {
     my $doc = XML::LibXML::Document->new();
     my $t1 = $doc->createTextNode( "bar1" );
     is( scalar( @cn ), 4, ' TODO : Add test name' );
     
     $e->normalize;
-    
+
+    @cn = $e->childNodes;
+    # TEST
+    is( scalar( @cn ), 2, ' TODO : Add test name' );
+
+    # TEST
+
+    ok(! defined $t2->parentNode, ' TODO : Add test name');
+    # TEST
+    ok(! defined $t3->parentNode, ' TODO : Add test name');
+}
+
+# 4.2 Normalization on a Document node
+{
+    my $doc = XML::LibXML::Document->new();
+    my $t1 = $doc->createTextNode( "bar1" );
+    my $t2 = $doc->createTextNode( "bar2" );
+    my $t3 = $doc->createTextNode( "bar3" );
+    my $e  = $doc->createElement("foo");
+    my $e2 = $doc->createElement("bar");
+    $doc->setDocumentElement($e);
+    $e->appendChild( $e2 );
+    $e->appendChild( $t1 );
+    $e->appendChild( $t2 );
+    $e->appendChild( $t3 );
+
+    my @cn = $e->childNodes;
+
+    # this is the correct behaviour for DOM. the nodes are still
+    # refered
+    # TEST
+    is( scalar( @cn ), 4, ' TODO : Add test name' );
+
+    $doc->normalize;
+
     @cn = $e->childNodes;
     # TEST
     is( scalar( @cn ), 2, ' TODO : Add test name' );