#!/usr/bin/perl

use XML::DT;
use Test::More tests=>4;

=head1 toxml - uso simple

=cut

is(toxml("a",{href=>"http://natura.di.uminho.p"},"a link"),
   '<a href="http://natura.di.uminho.p">a link</a>');

=head1 Dtstring and dt with empty handler = Identity function

=cut

$txt1=q{<html><head></head><body>
<ul>
  <li t="aaa">ex1</li>
  <li t="bbb">ex2</li>
  <li>ex3</li>
</ul>
</body></html>};

is(dtstring($txt1,()),$txt1);

=head1 Sorting a UL list by a T atribute

=cut

$t2in=q{<html><head></head><body>
<ul>
 <li t="zzz">ex1</li>
 <li t="bbb">ex2</li>
 <li t="aaa">ex3</li>
</ul>
</body></html>};

$t2out=q{<html><head></head><body>
<ul>
 <li t="aaa">ex3</li>
 <li t="bbb">ex2</li>
 <li t="zzz">ex1</li>
</ul>
</body></html>};

%h2=(-type => {ul => "SEQH"},
     li    => sub{$c} ,
    );

is(remsp(dtstring($t2in,%h2)),remsp($t2in));

%h3=(-type => {ul => "SEQH"},
     li    => sub{$c} ,
     ul    => sub{$c=[sort {$a->{t} cmp $b->{t}} @$c];toxml() },
    );

is(remsp(dtstring($t2in,%h3)),remsp($t2out));

sub remsp{  ### remove spaces near marcup in order to compare easier
 my $a=shift;
 $a =~ s/\s*</</g;
 $a =~ s/>\s</>/g;
 $a
}
