use strict; use Test::More; use WWW::Tumblr::ThemeParser; my $tests = get_tests(); plan tests => @$tests * 3; for my $test ( @$tests ) { diag $test->{comment}; my $p = WWW::Tumblr::ThemeParser->new( \$test->{html} ); is_deeply $p->tokens, $test->{tokens}; is_deeply $p->settings, $test->{settings}; my @tokens; while ( my $t = $p->get_token ) { push @tokens, $t; } is_deeply \@tokens, $test->{tokens}; } sub get_tests { return [ { comment => 'variable + block', html => '{Title}
    {block:Posts}
  1. {Body}
  2. {/block:Posts}
', tokens => [ [ 'TEXT', '' ], [ 'VAR', 'Title' ], [ 'TEXT', '
    ' ], [ 'SBLOCK', 'block:Posts' ], [ 'TEXT', '
  1. ' ], [ 'VAR', 'Body' ], [ 'TEXT', '
  2. ' ], [ 'EBLOCK', '/block:Posts' ], [ 'TEXT', '
' ], ], settings => {}, }, { comment => 'no slash on end-block tag', html => '{block:Posts}...{block:Posts}{block:Posts}...{/block:Posts}', tokens => [ [ 'SBLOCK', 'block:Posts' ], [ 'TEXT', '...' ], [ 'EBLOCK', '/block:Posts' ], [ 'SBLOCK', 'block:Posts' ], [ 'TEXT', '...' ], [ 'EBLOCK', '/block:Posts' ], ], settings => {}, }, { comment => 'custom colors', html => '', tokens => [ [ 'TEXT', '' ], ], settings => { color => { Background => '#eee' }, }, }, { comment => 'booleans', html => '{block:IfNotReversePagination}Previous Next{/block:IfNotReversePagination}{block:IfReversePagination}Next Previous{/block:IfReversePagination}', tokens => [ [ 'TEXT', '' ], [ 'SBLOCK', 'block:IfNotReversePagination' ], [ 'TEXT', 'Previous Next' ], [ 'EBLOCK', '/block:IfNotReversePagination' ], [ 'SBLOCK', 'block:IfReversePagination' ], [ 'TEXT', 'Next Previous' ], [ 'EBLOCK', '/block:IfReversePagination' ], [ 'TEXT', '' ], ], settings => { if => { 'Reverse pagination' => 0 }, }, }, ]; }