From: Vincent Pit Date: Sun, 18 Jul 2010 10:10:38 +0000 (+0200) Subject: Fix appending to a Set::Mod X-Git-Tag: v0.01~55 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=168a73df452b234d431ca830d3eb937bf89348ec;p=perl%2Fmodules%2FLaTeX-TikZ.git Fix appending to a Set::Mod And start testing mods in t/20-mod.t. --- diff --git a/MANIFEST b/MANIFEST index 3063aec..54bb4e7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -33,4 +33,5 @@ lib/LaTeX/TikZ/Set/Sequence.pm t/00-load.t t/01-api.t t/10-set.t +t/20-mod.t t/91-pod.t diff --git a/lib/LaTeX/TikZ/Set/Mod.pm b/lib/LaTeX/TikZ/Set/Mod.pm index 8444fea..e98b98a 100644 --- a/lib/LaTeX/TikZ/Set/Mod.pm +++ b/lib/LaTeX/TikZ/Set/Mod.pm @@ -69,7 +69,7 @@ sub add { } else { require LaTeX::TikZ::Set::Sequence; $set->_set(LaTeX::TikZ::Set::Sequence->new( - kids => $kid, + kids => [ $kid, @_ ], )); } diff --git a/t/20-mod.t b/t/20-mod.t new file mode 100644 index 0000000..477fdd1 --- /dev/null +++ b/t/20-mod.t @@ -0,0 +1,81 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 6 + 2 * 4; + +use LaTeX::TikZ; +use LaTeX::TikZ::Formatter; + +my $tikz = LaTeX::TikZ::Formatter->new( + format => '%d', +); + +sub check { + my ($set, $desc, $exp) = @_; + + 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'); +}; +is $@, '', 'creating a color mod doesn\'t croak'; + +my $foo = eval { + Tikz->raw('foo') + ->mod($red) +}; +is $@, '', 'creating a modded raw set doesn\'t croak'; + +check $foo, 'one modded raw set', <<'RES'; +\draw [color=red] foo ; +RES + +my $width = eval { + Tikz->width(25); +}; +is $@, '', 'creating a width mod doesn\'t croak'; + +eval { + $foo->mod($width); +}; +is $@, '', 'adding another mod doesn\'t croak'; + +check $foo, 'one double modded raw set', <<'RES'; +\draw [color=red,line width=4.0pt] foo ; +RES + +eval { + $foo->mod($red); +}; +is $@, '', 're-adding an previously set mod doesn\'t croak'; + +check $foo, 'one triple modded raw set (with duplicates)', <<'RES'; +\draw [color=red,line width=4.0pt] foo ; +RES + +my $bar = Tikz->raw('bar'); +eval { + $foo->add($bar); +}; +is $@, '', 'appending to a modded set doesn\'t croak'; + +check $foo, 'one triple modded sequence of raw sets (with duplicates)', <<'RES'; +\begin{scope} [color=red,line width=4.0pt] +\draw foo ; +\draw bar ; +\end{scope} +RES