#!/usr/bin/perl -I. use strict; use Test::More qw(no_plan); use HTML::Transmorgify; use HTML::Transmorgify::Metatags; use warnings; my $finished = 0; END { ok($finished, "finished"); } my $test_start_line = __LINE__+3; my @tests = split(/^>+TEST/m, <<'END_OF_TESTS'); >>>>>>>>>>>>>>>>>>TEST no magic stuff at all This is some text with some tags in it. None of these >>>>RESULT This is some text with some tags in it. None of these >>>>>>>>>>>>>>>>>>TEST In-tag unit test >>>>RESULT >>>>>>>>>>>>>>>>>>TEST In-tag define Some text. use it: . >>>>RESULT Some text. use it: 1 2 3. >>>>>>>>>>>>>>>>>>TEST simple block define This is some text with some tags in it. bar And now let's use it: >>>>RESULT This is some text with some tags in it. And now let's use it: bar >>>>>>>>>>>>>>>>>>TEST macro expand in a tag Some text 3. def >>>>RESULT Some text 3. >>>>>>>>>>>>>>>>>>TEST macro expand in a special tag Some text 4. def >>>>RESULT Some text 4. >>>>>>>>>>>>>>>>>>TEST macro "pointers" Stuff. foo value bar value foo Pointer is ''. Pointer indirect: ''. bar Pointer is ''. Pointer indirect: ''. >>>>RESULT Stuff. Pointer is 'foo'. Pointer indirect: 'foo value'. Pointer is 'bar'. Pointer indirect: 'bar value'. >>>>>>>>>>>>>>>>>>TEST macro defines macro Foo original bar baz Use bar: . Now use foo: . Now use bar again: . >>>>RESULT Foo Use bar: original bar. Now use foo: . Now use bar again: baz. >>>>>>>>>>>>>>>>>>TEST array lookup end >>>>RESULT two end >>>>>>>>>>>>>>>>>>TEST hash lookup end >>>>RESULT foo end >>>>>>>>>>>>>>>>>>TEST basic foreach Showing . end >>>>RESULT Showing one. Showing two. Showing three. end >>>>>>>>>>>>>>>>>>TEST basic if (true) simple1 is set >>>>>RESULT simple1 is set >>>>>>>>>>>>>>>>>>TEST basic if (false) simple1 is set >>>>>RESULT >>>>>>>>>>>>>>>>>>TEST basic else is set is not set ov is set ov is not set end >>>>>RESULT is set ov is not set end >>>>>>>>>>>>>>>>>>TEST nested foreach : end >>>>>RESULT one: 1 2 3 4 5 two: 1 2 3 4 5 three: 1 2 3 4 5 end >>>>>>>>>>>>>>>>>>TEST combined: foreach w/pointer elsif test got an if got a bar got a baz got a bof or else whew >>>>RESULT got an if 1 got a bar 2 got a baz 3 got a bof 4 or else 5 whew END_OF_TESTS shift(@tests); my $onebad = 0; my %vars = ( simple1 => 'value 1', foo1 => 'foo one', bar2 => 'bar two', baz3 => 'baz three', bof4 => 'bof four', array1 => [qw(one two three)], a3 => [qw(1 2 3 4 5)], hash1 => { key1 => { key2 => 'foo' }, other => 'bar' }, ); my $magic = HTML::Transmorgify->new(); $magic->mixin('HTML::Transmorgify::Metatags'); for my $t (@tests) { $t =~ /^ ([^\n]+)\n(?=((.*?)\n>+RESULT\n))\2(.*)/s or die "t='$t'"; my ($text, $input, $output) = ($1, $3, $4); chomp($output); undef %HTML::Transmorgify::compiled; my $res; eval { $res = $magic->process($input, { input_file => __FILE__, input_line => $test_start_line }, %vars); }; ok(! $@,"eval error at $text"); if (($@ || $res ne $output) && ! $onebad++) { local($HTML::Transmorgify::debug) = 1; undef %HTML::Transmorgify::compiled; pos($input) = 0; $res = $magic->process($input, { input_file => __FILE__, input_line => $test_start_line }, %vars); } is($res, $output, $text); exit if ($res ne $output); $test_start_line += ($t =~ tr/\n/\n/); } $finished = 1;