X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F20-mod.t;h=024a988350b05657420bf41d08d734ae3afbbb71;hb=9eaa7c633f6b14fe72e7a6b479bd198c93c7d8ff;hp=477fdd1fa2a87f3b7384d283b953862d5a5bb02f;hpb=168a73df452b234d431ca830d3eb937bf89348ec;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/20-mod.t b/t/20-mod.t index 477fdd1..024a988 100644 --- a/t/20-mod.t +++ b/t/20-mod.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 6 + 2 * 4; +use Test::More tests => 11 + 2 * 15; use LaTeX::TikZ; use LaTeX::TikZ::Formatter; @@ -15,6 +15,8 @@ my $tikz = LaTeX::TikZ::Formatter->new( 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); }; @@ -79,3 +81,153 @@ check $foo, 'one triple modded sequence of raw sets (with duplicates)', <<'RES'; \draw bar ; \end{scope} RES + +my $baz = eval { + Tikz->raw('baz') + ->mod($red); +}; +is $@, '', 'creating another colored raw set doesn\'t croak'; + +check [ $foo, $baz ], 'mods folding 1', <<'RES'; +\begin{scope} [color=red] +\begin{scope} [line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +\draw baz ; +\end{scope} +RES + +check [ $baz, $foo ], 'mods folding 2', <<'RES'; +\begin{scope} [color=red] +\draw baz ; +\begin{scope} [line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +\end{scope} +RES + +my $qux = eval { + Tikz->raw('qux') + ->mod($width); +}; +is $@, '', 'creating another raw set with modded width doesn\'t croak'; + +check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES'; +\begin{scope} [color=red] +\begin{scope} [line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +\draw baz ; +\end{scope} +\draw [line width=4.0pt] qux ; +RES + +check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES'; +\begin{scope} [line width=4.0pt] +\begin{scope} [color=red] +\draw foo ; +\draw bar ; +\end{scope} +\draw qux ; +\end{scope} +\draw [color=red] baz ; +RES + +check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES'; +\begin{scope} [color=red] +\draw baz ; +\begin{scope} [line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +\end{scope} +\draw [line width=4.0pt] qux ; +RES + +check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES'; +\draw [color=red] baz ; +\draw [line width=4.0pt] qux ; +\begin{scope} [color=red,line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +RES + +check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES'; +\begin{scope} [line width=4.0pt] +\draw qux ; +\begin{scope} [color=red] +\draw foo ; +\draw bar ; +\end{scope} +\end{scope} +\draw [color=red] baz ; +RES + +check [ $qux, $baz, $foo ], 'mods folding 8', <<'RES'; +\draw [line width=4.0pt] qux ; +\draw [color=red] baz ; +\begin{scope} [color=red,line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +RES + +my $seq = eval { + Tikz->seq($foo, $qux, $baz) + ->mod($red); +}; +is $@, '', 'creating a modded sequence set doesn\'t croak'; + +check $seq, 'mod covering 1', <<'RES'; +\begin{scope} [color=red] +\begin{scope} [line width=4.0pt] +\draw foo ; +\draw bar ; +\draw qux ; +\end{scope} +\draw baz ; +\end{scope} +RES + +my $seq2 = eval { + Tikz->seq($seq, $qux) + ->mod(Tikz->color('blue')); +}; +is $@, '', 'creating another modded sequence set doesn\'t croak'; + +check $seq2, 'mod covering 2', <<'RES'; +\begin{scope} [color=blue] +\begin{scope} [color=red] +\begin{scope} [line width=4.0pt] +\draw foo ; +\draw bar ; +\draw qux ; +\end{scope} +\draw baz ; +\end{scope} +\draw [line width=4.0pt] qux ; +\end{scope} +RES + +eval { + $foo->mod(Tikz->raw_mod('raw1')); + $seq->mod(Tikz->raw_mod('raw2')); +}; +is $@, '', 'creating and adding raw mods doesn\'t croak'; + +check $seq, 'mod covering 3', <<'RES'; +\begin{scope} [color=red,raw2] +\begin{scope} [line width=4.0pt] +\begin{scope} [raw1] +\draw foo ; +\draw bar ; +\end{scope} +\draw qux ; +\end{scope} +\draw baz ; +\end{scope} +RES