From: Vincent Pit Date: Wed, 27 Oct 2010 22:36:44 +0000 (+0200) Subject: Fix drawing empty sequences X-Git-Tag: rt87282~25 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=33b0a6db16fd5b70df1c151ff720bd07fbf34bdd;p=perl%2Fmodules%2FLaTeX-TikZ.git Fix drawing empty sequences --- diff --git a/lib/LaTeX/TikZ/Set/Sequence.pm b/lib/LaTeX/TikZ/Set/Sequence.pm index dfb30f7..afdc313 100644 --- a/lib/LaTeX/TikZ/Set/Sequence.pm +++ b/lib/LaTeX/TikZ/Set/Sequence.pm @@ -86,9 +86,12 @@ sub add { sub draw { my $set = shift; + my @kids = $set->kids; + return [ ] unless @kids; + List::Util::reduce { LaTeX::TikZ::Scope::fold($a, $b) } map $_->draw(@_), - $set->kids; + @kids; } LaTeX::TikZ::Interface->register( diff --git a/t/10-set.t b/t/10-set.t index 4ddac3c..6ff94ef 100644 --- a/t/10-set.t +++ b/t/10-set.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 12 + 2 * 7; +use Test::More tests => 19 + 2 * 14; use LaTeX::TikZ; @@ -101,6 +101,72 @@ check $seq3, 'two different raw sets and an extended sequence', <<'RES'; \draw foo ; RES +my $seq4 = eval { + Tikz->seq; +}; +is $@, '', 'creating an empty sequence doesn\'t croak'; + +check $seq4, 'an empty sequence', ''; + +$seq4 = eval { + Tikz->seq(Tikz->seq); +}; +is $@, '', 'creating a sequence that contains an empty sequence doesn\'t croak'; + +check $seq4, 'a sequence that contains an empty sequence', ''; + +$seq4 = eval { + Tikz->seq($foo, Tikz->seq); +}; +is $@, '', + 'creating a sequence that contains a set and an empty sequence doesn\'t croak'; + +check $seq4, 'a sequence that contains a set and an empty sequence', <<'RES'; +\draw foo ; +RES + +$seq4 = eval { + Tikz->seq(Tikz->seq, $foo); +}; +is $@, '', + 'creating a sequence that contains an empty sequence and a set doesn\'t croak'; + +check $seq4, 'a sequence that contains an empty sequence and a set', <<'RES'; +\draw foo ; +RES + +$seq4 = eval { + Tikz->seq($foo, $bar, Tikz->seq); +}; +is $@, '', +'creating a sequence that contains 2 sets and an empty sequence doesn\'t croak'; + +check $seq4, 'a sequence that contains 2 sets and an empty sequence', <<'RES'; +\draw foo ; +\draw bar ; +RES + +$seq4 = eval { + Tikz->seq($foo, Tikz->seq, $bar); +}; +is $@, '', 'creating a sequence that contains a set, an empty sequence, a set doesn\'t croak'; + +check $seq4, 'a sequence that contains a set, an empty sequence, a set',<<'RES'; +\draw foo ; +\draw bar ; +RES + +$seq4 = eval { + Tikz->seq(Tikz->seq, $foo, $bar); +}; +is $@, '', +'creating a sequence that contains an empty sequence and 2 sets'; + +check $seq4, 'a sequence that contains an empty sequence and 2 sets', <<'RES'; +\draw foo ; +\draw bar ; +RES + sub failed_valid { my ($tc) = @_; qr/Validation failed for '\Q$tc\E'/;