X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F20-mod.t;h=878a72b2234f25a3ca0ba7c03d3c9c5b4072c370;hb=03788848f1b2d570c82eb682bd45bc0d01c5223b;hp=d8407108742225af6388c1554af1609f33badc9d;hpb=ab2e6e400073c35ae59b532ac8a9fb8f40fd1a3c;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/20-mod.t b/t/20-mod.t index d840710..878a72b 100644 --- a/t/20-mod.t +++ b/t/20-mod.t @@ -3,12 +3,11 @@ use strict; use warnings; -use Test::More tests => 6 + 2 * 4; +use Test::More tests => 20 + 2 * 22; use LaTeX::TikZ; -use LaTeX::TikZ::Formatter; -my $tikz = LaTeX::TikZ::Formatter->new( +my $tikz = Tikz->formatter( format => '%d', ); @@ -46,6 +45,27 @@ check $foo, 'one modded raw set', <<'RES'; \draw [color=red] foo ; RES +my $foo2 = eval { + Tikz->raw('foo') + ->mod('->') +}; +is $@, '', 'creating a modded raw set from a string doesn\'t croak'; + +check $foo2, 'one modded raw set from a string', <<'RES'; +\draw [->] foo ; +RES + +sub failed_valid { + my ($tc) = @_; + qr/Validation failed for '\Q$tc\E'/; +} + +eval { + Tikz->raw([ 'fail' ]) + ->mod(Tikz->raw('epic')); +}; +like $@, failed_valid('LaTeX::TikZ::Mod'), 'trying to use a non LTM mod croaks'; + my $width = eval { Tikz->width(25); }; @@ -70,14 +90,256 @@ check $foo, 'one triple modded raw set (with duplicates)', <<'RES'; RES my $bar = Tikz->raw('bar'); -eval { - $foo->add($bar); +$foo = eval { + Tikz->seq( + Tikz->raw('foo'), + $bar + )->mod($red, $width); +}; +is $@, '', 'setting two mods in a row doesn\'t croak'; + +check $foo, 'one triple modded sequence of raw sets', <<'RES'; +\begin{scope} [color=red,line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +RES + +my $nested = eval { + Tikz->seq( + Tikz->seq(Tikz->raw("foo")) + ->mod($red) + )->mod($width) +}; +is $@, '', 'creating nested modded sequences doesn\'t croak'; + +check $nested, 'nested modded sequences', <<'RES'; +\draw [line width=4.0pt,color=red] foo ; +RES + +my $baz = eval { + Tikz->raw('baz') + ->mod($red); +}; +is $@, '', 'creating another colored raw set doesn\'t croak'; + +check Tikz->seq($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 Tikz->seq($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 $@, '', 'appending to a modded set doesn\'t croak'; +is $@, '', 'creating another raw set with modded width doesn\'t croak'; + +check Tikz->seq($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 Tikz->seq($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 Tikz->seq($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 $foo, 'one triple modded sequence of raw sets (with duplicates)', <<'RES'; +check Tikz->seq($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 Tikz->seq($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 Tikz->seq($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 + +eval { + $baz->mod(Tikz->raw_mod($_)) for qw/raw2 raw3/; +}; +is $@, '', 'creating and adding another raw mod doesn\'t croak'; + +check $seq, 'mod covering 4', <<'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 [raw2,raw3] baz ; +\end{scope} +RES + +eval { + $bar->mod(Tikz->width(50)); +}; +is $@, '', 'creating and adding another width mod doesn\'t croak'; + +check $seq, 'mod covering 5', <<'RES'; +\begin{scope} [color=red,raw2] +\begin{scope} [line width=4.0pt] +\begin{scope} [raw1] +\draw foo ; +\draw [line width=8.0pt] bar ; +\end{scope} +\draw qux ; +\end{scope} +\draw [raw2,raw3] baz ; +\end{scope} +RES + +my ($fred, $fblue) = eval { + map Tikz->fill($_), qw/red blue/; +}; +is $@, '', 'creating two fill mods doesn\'t croak'; + +$seq = eval { + Tikz->seq( + Tikz->raw("foo") + ->mod($fred) + )->mod($fred); +}; +is $@, '', 'creating a structure with two identical fill mods doesn\'t croak'; + +check $seq, 'mod covering 6', <<'RES'; +\draw [fill=red] foo ; +RES + +$seq = eval { + Tikz->seq( + Tikz->raw("foo") + ->mod($fblue) + )->mod($fred); +}; +is $@, '', 'creating a structure with two different fill mods doesn\'t croak'; + +check $seq, 'mod covering 7', <<'RES'; +\draw [fill=red,fill=blue] foo ; +RES + +$seq = eval { + Tikz->seq( + Tikz->raw("foo") + ->mod($red) + )->mod($fred); +}; +is $@, '', 'creating a structure with color and fill mods doesn\'t croak'; + +check $seq, 'mod covering 8', <<'RES'; +\draw [fill=red,color=red] foo ; +RES