X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F30-functor.t;h=64d7d4b6023e61c398fdd5fb09864dda41b6652c;hb=1ef0d773dfe4f90087af6a39b06061eaadb44a65;hp=30289c227be85a1a875ea24f0334bb3c54584fe3;hpb=77014f7c9da229da3785af0718f77412cb7756f9;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/30-functor.t b/t/30-functor.t index 30289c2..64d7d4b 100644 --- a/t/30-functor.t +++ b/t/30-functor.t @@ -3,33 +3,17 @@ use strict; use warnings; -use Test::More tests => 5 + 2 * 5; +use Test::More tests => 10 + 2 * 7; use LaTeX::TikZ; -my $tikz = Tikz->formatter( +use lib 't/lib'; +use LaTeX::TikZ::TestHelper; + +using Tikz->formatter( format => '%d', ); -sub check { - my ($set, $desc, $exp) = @_; - - local $Test::Builder::Level = $Test::Builder::Level + 1; - - my ($head, $decl, $body) = eval { - $tikz->render(ref $set eq 'ARRAY' ? @$set : $set); - }; - is $@, '', "$desc: no error"; - - unless (ref $exp eq 'ARRAY') { - $exp = [ split /\n/, $exp ]; - } - unshift @$exp, '\begin{tikzpicture}'; - push @$exp, '\end{tikzpicture}'; - - is_deeply $body, $exp, $desc; -} - my $translate = eval { Tikz->functor( 'LaTeX::TikZ::Set::Point' => sub { @@ -122,7 +106,43 @@ check $seq3, 'the stripped sequence', <<'RES'; \draw (-2cm,1cm) -- (2cm,1cm) ; RES -$tikz = eval { +my $special = eval { + Tikz->functor( + '+LaTeX::TikZ::Mod' => sub { die "mod\n" }, + '+LaTeX::TikZ::Set' => sub { die "set\n" }, + ); +}; +is $@, '', 'creating a special functor with + rules doesn\'t croak'; + +eval { $seq->$special }; +is $@, "set\n", 'special functor with + rules eats everything properly'; + +$special = eval { + Tikz->functor( + '+LaTeX::TikZ::Mod' => sub { die "mod\n" }, + '+LaTeX::TikZ::Set' => sub { die "set\n" }, + 'LaTeX::TikZ::Set::Point' => sub { Tikz->point(7) }, + 'LaTeX::TikZ::Set::Op' => sub { Tikz->raw('moo') }, + ); +}; +is $@, '', 'creating a special functor with + and normal rules doesn\'t croak'; + +my $res = eval { Tikz->point(3, 4)->$special }; +is $@, '', 'special functor with + and normal rules orders its rules properly'; + +check $res, 'the result of the special functor', <<'RES'; +\draw (7cm,0cm) ; +RES + +$res = eval { Tikz->raw('hlagh')->$special }; +is $@, '', + 'special functor with + and normal rules orders its rules properly again'; + +check $res, 'the result of the special functor', <<'RES'; +\draw moo ; +RES + +using eval { Tikz->formatter( origin => [ -1, 1 ], ); @@ -141,4 +161,3 @@ check $seq, 'a sequence translated by an origin', <<'RES'; \end{scope} \end{scope} RES -