X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F20-mod.t;h=191c150bdafe48b8502842d1b712a5e14fb4e146;hb=0fb9961e1a5172180e428b49f67e2120835c9e3c;hp=256cbdd58881121400e18118690e1db9d0f26ffb;hpb=aba26c835113a0332c5480e99f86bfa67111de84;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/20-mod.t b/t/20-mod.t index 256cbdd..191c150 100644 --- a/t/20-mod.t +++ b/t/20-mod.t @@ -3,34 +3,17 @@ use strict; use warnings; -use Test::More tests => 19 + 2 * 20; +use Test::More tests => 23 + 2 * 24; use LaTeX::TikZ; -use LaTeX::TikZ::Formatter; -my $tikz = LaTeX::TikZ::Formatter->new( +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 $red = eval { Tikz->color('red'); }; @@ -46,6 +29,54 @@ 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 $scale = eval { + Tikz->scale(2); +}; +is $@, '', 'creating a scale mod doesn\'t croak'; + +$foo2 = eval { + Tikz->raw('foo') + ->mod($scale); +}; +is $@, '', 'applying a scale mod doesn\'t croak'; + +check $foo2, 'a raw set with a scale mod', <<'RES'; +\draw [scale=2.000] foo ; +RES + +$foo2 = eval { + Tikz->union( + Tikz->raw('foo') + ->mod($scale), + )->mod(Tikz->scale(4)); +}; +is $@, '', 'applying two scale mods doesn\'t croak'; + +check $foo2, 'a union of a raw set with two scale mods', <<'RES'; +\draw [scale=4.000] foo ; +RES + my $width = eval { Tikz->width(25); }; @@ -70,56 +101,31 @@ 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 $@, '', 'appending to a modded set doesn\'t croak'; +is $@, '', 'setting two mods in a row doesn\'t croak'; -check $foo, 'one triple modded sequence of raw sets (with duplicates)', <<'RES'; +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 $set = Tikz->raw('wut'); - -my $set_mod = eval { - $set->mod; -}; -is $@, '', 'calling empty mod out of a set doesn\'t croak'; -is "$set_mod", "$set", 'calling empty mod out of a set returns the set'; - -my $new = eval { - $set->mod(Tikz->raw_mod('raw1')); -}; -is $@, '', - 'creating and applying a raw mod on a set in scalar context doesn\'t croak'; -is ref($new), 'LaTeX::TikZ::Set::Mod', 'new set is of the right kind'; -isnt "$new", "$set", 'new set is different from the old one'; - -check $set, '', <<'RES'; -\draw wut ; -RES - -check $new, '', <<'RES'; -\draw [raw1] wut ; -RES - -eval { - $set->mod(Tikz->raw_mod('raw2')); - (); +my $nested = eval { + Tikz->seq( + Tikz->seq(Tikz->raw("foo")) + ->mod($red) + )->mod($width) }; -is $@, '', - 'creating and applying a raw mod on a set in void context doesn\'t croak'; -is ref($new), 'LaTeX::TikZ::Set::Mod', 'new set is of the right kind'; +is $@, '', 'creating nested modded sequences doesn\'t croak'; -check $set, '', <<'RES'; -\draw [raw2] wut ; -RES - -check $new, '', <<'RES'; -\draw [raw1] wut ; +check $nested, 'nested modded sequences', <<'RES'; +\draw [line width=4.0pt,color=red] foo ; RES my $baz = eval { @@ -128,7 +134,7 @@ my $baz = eval { }; is $@, '', 'creating another colored raw set doesn\'t croak'; -check [ $foo, $baz ], 'mods folding 1', <<'RES'; +check Tikz->seq($foo, $baz), 'mods folding 1', <<'RES'; \begin{scope} [color=red] \begin{scope} [line width=4.0pt] \draw foo ; @@ -138,7 +144,7 @@ check [ $foo, $baz ], 'mods folding 1', <<'RES'; \end{scope} RES -check [ $baz, $foo ], 'mods folding 2', <<'RES'; +check Tikz->seq($baz, $foo), 'mods folding 2', <<'RES'; \begin{scope} [color=red] \draw baz ; \begin{scope} [line width=4.0pt] @@ -154,7 +160,7 @@ my $qux = eval { }; is $@, '', 'creating another raw set with modded width doesn\'t croak'; -check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES'; +check Tikz->seq($foo, $baz, $qux), 'mods folding 3', <<'RES'; \begin{scope} [color=red] \begin{scope} [line width=4.0pt] \draw foo ; @@ -165,7 +171,7 @@ check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES'; \draw [line width=4.0pt] qux ; RES -check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES'; +check Tikz->seq($foo, $qux, $baz), 'mods folding 4', <<'RES'; \begin{scope} [line width=4.0pt] \begin{scope} [color=red] \draw foo ; @@ -176,7 +182,7 @@ check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES'; \draw [color=red] baz ; RES -check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES'; +check Tikz->seq($baz, $foo, $qux), 'mods folding 5', <<'RES'; \begin{scope} [color=red] \draw baz ; \begin{scope} [line width=4.0pt] @@ -187,7 +193,7 @@ check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES'; \draw [line width=4.0pt] qux ; RES -check [ $baz, $qux, $foo ], 'mods folding 6', <<'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] @@ -196,7 +202,7 @@ check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES'; \end{scope} RES -check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES'; +check Tikz->seq($qux, $foo, $baz), 'mods folding 7', <<'RES'; \begin{scope} [line width=4.0pt] \draw qux ; \begin{scope} [color=red] @@ -207,7 +213,7 @@ check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES'; \draw [color=red] baz ; RES -check [ $qux, $baz, $foo ], 'mods folding 8', <<'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] @@ -273,7 +279,7 @@ check $seq, 'mod covering 3', <<'RES'; RES eval { - $baz->mod(Tikz->raw_mod($_)) for qw/raw2 raw3/; + $baz->mod(Tikz->raw_mod($_)) for qw; }; is $@, '', 'creating and adding another raw mod doesn\'t croak'; @@ -286,6 +292,65 @@ check $seq, 'mod covering 4', <<'RES'; \end{scope} \draw qux ; \end{scope} -\draw [raw3] baz ; +\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; +}; +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