Text-TagTemplate

 view release on metacpan or  search on metacpan

t/basic.t  view on Meta::CPAN

N: 7
1: TAG ONE, 3: TAG THREE
N: 8
1: TAG ONE, 3: TAG THREE
N: 9
1: TAG ONE, 3: TAG THREE
N: A
eot
is( $t->parse_list_files( +[ 6, 7, 8, 9, 'A' ] ),
    $expected,
    "parse_list_file() - using listref supplied to function.");

is( $t->parse_list_files( +[ 6, 7, 8, 9, 'A' ], 'test-entry.htmlf' ),
    $expected,
    "parse_list_file() - using listref and entry file supplied to function.");

is( $t->parse_list_files( +[ 6, 7, 8, 9, 'A' ], 'test-entry.htmlf', 'test-join.htmlf' ),
    $expected,
    "parse_list_file() - using listref, entry file, and join file supplied to function.");

is( $t->parse_list_files( +[ 6, 7, 8, 9, 'A' ], 'test-entry.htmlf', 'test-join.htmlf', sub { return +{ N => $_[ 0 ] } } ),
    $expected,
    "parse_list_file() - using listref, entry file, join file, and callback supplied to function.");
    
is( $t->parse_list_files(
       +[ 6, 7, 8, 9, 'A' ],
       'test-entry.htmlf',
       'test-join.htmlf',
       sub { return +{ N => $_[ 0 ] } },
       1 => 'TAG ONE', 3 => 'TAG THREE'       
      ),
    $expected,
    "parse_list_file() - using listref, entry file, join file, callback, and tags hash supplied to function.");
 
is( $t->parse_list_files(
       +[ 6, 7, 8, 9, 'A' ],
       'test-entry.htmlf',
       'test-join.htmlf',
       sub { return +{ N => $_[ 0 ] } },
       { 1 => 'TAG ONE', 3 => 'TAG THREE' }      
      ),
    $expected,
    "parse_list_file() - using listref, entry file, join file, callback, and tags hashref supplied to function.");

$expected = qq{W: <#W P="Space: Tab:\tCR:\nLT:&lt;GT:&gt;Equals:&#061;Amp:&amp;Quote:&quot;">};
$t->unknown_action( 'IGNORE' );
is($t->parse(  $expected ), $expected, "Parsing with unknown_action() to IGNORE.");

$t->add_tag( W => sub {
	my %params = %{ $_[ 0 ] };
	return $params{ P };
} );

my $string = qq{W: <#W P="Space: Tab:\tCR:\nLT:&lt;GT:&gt;Equals:&#061;Amp:&amp;Quote:&quot;">};
$expected = qq{W: Space: Tab:\tCR:\nLT:<GT:>Equals:=Amp:&Quote:"};
is($t->parse($string),
   $expected,
   "Parameters with whitespace and interesting characters are handled right.");


$t->add_tag( EMBEDTEST => sub {
	my %params = %{ $_[ 0 ] };
        my $result;
        foreach my $attr (sort keys %params) {
             $result .= qq{$attr="$params{$attr}"};
        }
	return $result;
} );
$t->add_tag( EMBED_1 => sub {
	my %params = %{ $_[ 0 ] };
	return $params{ATTR_1};
} );
$string = qq{EMBEDDED TAG: <#EMBEDTEST name="<#EMBED_1 ATTR_1="hello">">};
$expected = q{EMBEDDED TAG: NAME="hello"} ;
is($t->parse($string),$expected,"Tags embedded in tags are handled correctly.");

$string = qq{EMBEDDED TAG: <#EMBEDTEST name="<#EMBED_1 ATTR_1="hello=world">">};
$expected = q{EMBEDDED TAG: NAME="hello=world"};
is($t->parse($string),$expected,"Are attribute values containing '=' in embedded tags are handled correctly?");

$expected = 'Zero: 0';
$t->add_tag( ZERO => sub { 0; } );
is($t->parse('Zero: <#ZERO>'),$expected,"Is 0 (zero) handled properly as a replacement value?");


my $tag_start    = '&start;';
my $tag_content = '[^&]*';
my $tag_end      = '&end;';
my $regex = qr/$tag_start($tag_content)$tag_end/;
# print "Change the tag pattern to '$regex'\n";
$t->tag_start('&start;');
$t->tag_contents('[^&]*');
$t->tag_end('&end;');
is($t->tag_pattern, $regex, "tag_start(), tag_contents(), tag_end(), tag_pattern() all work?");


$expected = 'Hello 0';
$t->add_tag( ZERO => sub { 0; } );
is($t->parse( 'Hello &start;ZERO&end;' ),
   $expected,
   "Parse using the new tag_pattern $regex");


$tag_start = '/\*';
$tag_content = '[^*]*';
$tag_end     = '\*/';
$regex = qr/$tag_start($tag_content)$tag_end/;
$t->tag_start($tag_start);
$t->tag_contents($tag_content);
$t->tag_end($tag_end);
is($t->tag_pattern,$regex,"Changing tag_pattern again.");

$expected = qq{W: Space: Tab:\tCR:\nLT:<GT:>Equals:=Amp:&Quote:" */**};
$string = qq{W: /*W P="Space: Tab:\tCR:\nLT:&lt;GT:&gt;Equals:&#061;Amp:&amp;Quote:&quot;"*/ */**};
is($t->parse($string), $expected, "parse() using tag_pattern $regex");



( run in 2.085 seconds using v1.01-cache-2.11-cpan-71847e10f99 )