use strict;
use HTML::Tiny;
use Test::More tests => 18;
ok my $h = HTML::Tiny->new, 'Create succeeded';
ok my $h_html = HTML::Tiny->new( mode => 'html' ),
'Create succeeded (mode HTML)';
common_checks( $h );
common_checks( $h_html, ' (mode HTML)' );
is $h->stringify( [ \'br' ] ), '
', 'br OK';
is $h->stringify( [ \'input', { name => 'myfield', type => 'text' } ] ),
'', 'input OK';
is $h->stringify( [ \'img', { src => 'pic.jpg' } ] ),
'
',
'img OK';
is $h_html->stringify( [ \'br' ] ), '
', 'br OK (mode HTML)';
is $h_html->stringify(
[ \'input', { name => 'myfield', type => 'text' } ]
),
'', 'input OK (mode HTML)';
is $h_html->stringify( [ \'img', { src => 'pic.jpg' } ] ),
'
', 'img OK (mode HTML)';
sub common_checks {
my $h = shift;
my $mode = shift || '';
is $h->stringify( [ \'p', 'hello, world' ] ),
"
hello, world
\n", 'p OK' . $mode; is $h->stringify( [ \'a', { href => 'http://hexten.net', title => 'Hexten' }, 'Hexten' ] ), 'Hexten', 'a OK' . $mode; is $h->stringify( [ \'textarea' ] ), '', 'empty tag OK' . $mode; is $h->stringify( [ \'table', [ \'tr', [ \'th', 'Name', 'Score', 'Position' ], [ \'td', 'Therese', 90, 1 ], [ \'td', 'Chrissie', 85, 2 ], [ \'td', 'Andy', 50, 3 ] ] ] ), "| Name | Score | Position |
|---|---|---|
| Therese | 90 | 1 |
| Chrissie | 85 | 2 |
| Andy | 50 | 3 |
Hello, World
\nSecond para
\n" . "\n\n", 'complex HTML OK' . $mode; }