Web::Chain project:    Web/Pro/t/Web-Pro-Transform.t


     # Test file created outside of h2xs framework.
# Run this like so: `perl Web-Pro-Transform.t'
#   doom@kzsu.stanford.edu     2004/10/09 06:57:26

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use warnings;
use strict;
$|=1;

use Test::More;
BEGIN { plan tests => 3 };

use Web::Definitions qw( $DEBUG 
                        );

# use Web::Pro::Transform qw(:all);
use Web::Pro::Transform qw( text2xml 
                            xml2text
                            text2html
                            html2text
                          );

ok(1); # If we made it this far, we're ok.

#########################

my $raw_text = <<RAWTEXT;
Not too much too see here. 
Move along.  
Yada  Oh yeah, gimme a   LINK
Okay? so that was a link.

RAWTEXT


my $expected_xmlesque = <<EXPECTORATED;
<NODEBODY>Not too much too see here. 
Move along.  
Yada  Oh yeah, gimme a   <A HREF="LINK.html">LINK</A>
Okay? so that was a link.
</NODEBODY>
EXPECTORATED

{
  my $xmlesque_ref = text2xml(\$raw_text);
#  ($DEBUG) && print STDERR "${ $xmlesque_ref }\n";

  is( ${ $xmlesque_ref }, $expected_xmlesque, "Test of text2xml on simple df-style text."); 

  my $inverse_trans_ref = xml2text($xmlesque_ref);
  is( ${ $inverse_trans_ref }, $raw_text, "Test of xml2text doing the inverse transform.");


}

my $expected_html = <<SPLAT;
Not too much too see here. 
Move along.  
Yada  Oh yeah, gimme a   <A HREF="LINK.html">LINK</A>
Okay? so that was a link.

SPLAT

{
  my $html_ref = text2html(\$raw_text);
#  ($DEBUG) && print STDERR "${ $html_ref }\n";

  is( ${ $html_ref }, $expected_html, "Test of text2html on simple df-style text."); 

  my $inverse_trans_ref = html2text($html_ref);
  is( ${ $inverse_trans_ref }, $raw_text, "Test of html2text doing the inverse transform.");

  my $multiple_inverse_ref = html2text( text2html( html2text( text2html( \$raw_text ))));
  is( ${ $multiple_inverse_ref }, $raw_text, "Test multiple transform/inverse transform steps return to original form.");

}

     

Joseph Brenner, Sat Nov 6 17:04:11 2004