From: Vincent Pit Date: Sun, 18 Jul 2010 00:44:34 +0000 (+0200) Subject: Basic set tests in t/10-set.t X-Git-Tag: v0.01~60 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=30cc7e83ac006f071c3fe119d696525d6637ff1d;p=perl%2Fmodules%2FLaTeX-TikZ.git Basic set tests in t/10-set.t --- diff --git a/MANIFEST b/MANIFEST index 812e676..3063aec 100644 --- a/MANIFEST +++ b/MANIFEST @@ -32,4 +32,5 @@ lib/LaTeX/TikZ/Set/Rectangle.pm lib/LaTeX/TikZ/Set/Sequence.pm t/00-load.t t/01-api.t +t/10-set.t t/91-pod.t diff --git a/t/10-set.t b/t/10-set.t new file mode 100644 index 0000000..3908642 --- /dev/null +++ b/t/10-set.t @@ -0,0 +1,76 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 5 + 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 $foo = eval { + Tikz->raw('foo'); +}; +is $@, '', 'creating a raw set doesn\'t croak'; + +check $foo, 'one raw set', <<'RES'; +\draw foo ; +RES + +my $seq2 = eval { + Tikz->seq($foo, $foo); +}; +is $@, '', 'creating a 2-sequence doesn\'t croak'; + +check $seq2, 'two identical raw sets', <<'RES'; +\draw foo ; +\draw foo ; +RES + +my $bar = eval { + Tikz->raw('bar'); +}; +is $@, '', 'creating another raw set doesn\'t croak'; + +$seq2 = eval { + Tikz->seq($foo, $bar); +}; +is $@, '', 'creating another 2-sequence doesn\'t croak'; + +check $seq2, 'two different raw sets', <<'RES'; +\draw foo ; +\draw bar ; +RES + +my $seq3 = eval { + Tikz->seq($bar, $seq2, $foo); +}; +is $@, '', 'creating a complex sequence doesn\'t croak'; + +check $seq3, 'two different raw sets and a sequence', <<'RES'; +\draw bar ; +\draw foo ; +\draw bar ; +\draw foo ; +RES