X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F30-functor.t;h=e455a9d6e1a59bdd73168c6e15257afa0d52097f;hb=0e7c2e9d009574e0d337db855d433a8e07d04512;hp=cda1ab1b164a63c188198324afea7eecbe2d5a5b;hpb=594156dad44851e8a31499dfb83b9c6f089abdd4;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/30-functor.t b/t/30-functor.t index cda1ab1..e455a9d 100644 --- a/t/30-functor.t +++ b/t/30-functor.t @@ -1,35 +1,19 @@ -#!perl +#!perl -T 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 { @@ -53,7 +37,11 @@ my $seq = Tikz->seq( Tikz->raw('foo'), Tikz->point(2), Tikz->line(-1 => 3) - ->clip(Tikz->circle(1, 1)) + ->clip(Tikz->circle(1, 1)), + Tikz->union( + Tikz->chain(4 => '--' => [ -3, 2 ]), + Tikz->join('-|' => [ -1, 0 ], [ 0, 1 ]), + ), ) ->clip(Tikz->rectangle([0, -1] => [2, 3])); @@ -72,6 +60,7 @@ check $seq, 'the original sequence', <<'RES'; \clip (1cm,0cm) circle (1cm) ; \draw (-1cm,0cm) -- (3cm,0cm) ; \end{scope} +\draw (4cm,0cm) -- (-3cm,2cm) (-1cm,0cm) -| (0cm,1cm) ; \end{scope} RES @@ -85,6 +74,7 @@ check $seq2, 'the translated sequence', <<'RES'; \clip (0cm,1cm) circle (1cm) ; \draw (-2cm,1cm) -- (2cm,1cm) ; \end{scope} +\draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ; \end{scope} RES @@ -112,6 +102,7 @@ check $seq2, 'the original sequence', <<'RES'; \clip (0cm,1cm) circle (1cm) ; \draw (-2cm,1cm) -- (2cm,1cm) ; \end{scope} +\draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ; \end{scope} RES @@ -120,9 +111,46 @@ check $seq3, 'the stripped sequence', <<'RES'; \draw foo ; \draw (1cm,1cm) ; \draw (-2cm,1cm) -- (2cm,1cm) ; +\draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ; +RES + +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::Path' => 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 -$tikz = eval { +$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 ], ); @@ -139,6 +167,6 @@ check $seq, 'a sequence translated by an origin', <<'RES'; \clip (0cm,1cm) circle (1cm) ; \draw (-2cm,1cm) -- (2cm,1cm) ; \end{scope} +\draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ; \end{scope} RES -