From: Vincent Pit Date: Sun, 18 Jul 2010 23:07:24 +0000 (+0200) Subject: Test clips X-Git-Tag: v0.01~42 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=038a21c751dcd34f83857e095d935bfa07b6b679;p=perl%2Fmodules%2FLaTeX-TikZ.git Test clips --- diff --git a/MANIFEST b/MANIFEST index d765e1d..4d8c347 100644 --- a/MANIFEST +++ b/MANIFEST @@ -34,4 +34,5 @@ t/01-api.t t/10-set.t t/20-mod.t t/21-layer.t +t/22-clip.t t/91-pod.t diff --git a/lib/LaTeX/TikZ/Set.pm b/lib/LaTeX/TikZ/Set.pm index da636a4..78b53ce 100644 --- a/lib/LaTeX/TikZ/Set.pm +++ b/lib/LaTeX/TikZ/Set.pm @@ -133,7 +133,7 @@ sub clip { $_[0]->mod( map { - $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new($_) + $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new(clip => $_) } @_[1 .. $#_] ) } diff --git a/t/22-clip.t b/t/22-clip.t new file mode 100644 index 0000000..800be76 --- /dev/null +++ b/t/22-clip.t @@ -0,0 +1,156 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 2 + 2 * 9; + +use LaTeX::TikZ; + +my $tikz = 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 $clip1 = Tikz->raw('clip1'); +my $clip2 = Tikz->raw('clip2'); + +my $foo = eval { + Tikz->raw('foo') + ->clip($clip1); +}; +is $@, '', 'creating a clipping a raw path with ->clip doesn\'t croak'; + +check $foo, 'one clipped raw set', <<'RES'; +\begin{scope} +\clip clip1 ; +\draw foo ; +\end{scope} +RES + +my $bar = eval { + Tikz->raw('bar') + ->mod(Tikz->clip(Tikz->raw('clip1'))); +}; +is $@, '', 'creating a clipping a raw path with ->mod doesn\'t croak'; + +check $bar, 'another clipped raw set', <<'RES'; +\begin{scope} +\clip clip1 ; +\draw bar ; +\end{scope} +RES + +my $seq = Tikz->seq($foo, $bar); + +check $seq, 'mods folding with clips 1', <<'RES'; +\begin{scope} +\clip clip1 ; +\draw foo ; +\draw bar ; +\end{scope} +RES + +my $baz = Tikz->raw('baz') + ->clip($clip2); + +check Tikz->seq($seq, $baz), 'mods folding with clips 2', <<'RES'; +\begin{scope} +\clip clip1 ; +\draw foo ; +\draw bar ; +\end{scope} +\begin{scope} +\clip clip2 ; +\draw baz ; +\end{scope} +RES + +check Tikz->seq($baz, $seq), 'mods folding with clips 3', <<'RES'; +\begin{scope} +\clip clip2 ; +\draw baz ; +\end{scope} +\begin{scope} +\clip clip1 ; +\draw foo ; +\draw bar ; +\end{scope} +RES + +my $seq2 = Tikz->seq($seq, $baz) + ->clip($clip1); + +check $seq2, 'mods folding with clips 4', <<'RES'; +\begin{scope} +\clip clip1 ; +\draw foo ; +\draw bar ; +\begin{scope} +\clip clip2 ; +\draw baz ; +\end{scope} +\end{scope} +RES + +$seq2 = Tikz->seq($seq, $baz) + ->clip($clip2); + +check $seq2, 'mods folding with clips 5', <<'RES'; +\begin{scope} +\clip clip2 ; +\begin{scope} +\clip clip1 ; +\draw foo ; +\draw bar ; +\end{scope} +\draw baz ; +\end{scope} +RES + +$seq2->clip($clip1); + +check $seq2, 'mods folding with clips 6', <<'RES'; +\begin{scope} +\clip clip2 ; +\begin{scope} +\clip clip1 ; +\draw foo ; +\draw bar ; +\draw baz ; +\end{scope} +\end{scope} +RES + +$seq2->mod(Tikz->color('red')); + +check $seq2, 'mods folding with clips 7', <<'RES'; +\begin{scope} [color=red] +\clip clip2 ; +\begin{scope} +\clip clip1 ; +\draw foo ; +\draw bar ; +\draw baz ; +\end{scope} +\end{scope} +RES +