X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=blobdiff_plain;f=t%2F12-geo.t;h=3a7eef7e65a32dd702f49ac12b476d19915158f9;hp=ab56eaac3049175cb7777e7c4c529a33fe2ff3e8;hb=080eb1e263eb7c3700a9ebfd96522eaa534a0b6c;hpb=d6ce9bd1690e1ed3ceb9beb90380c94a4efa6e54 diff --git a/t/12-geo.t b/t/12-geo.t index ab56eaa..3a7eef7 100644 --- a/t/12-geo.t +++ b/t/12-geo.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 11 + 2 * 10; +use Test::More tests => (11 + 2 * 5) + 2 * (10 + 2 * 3); use Math::Complex; @@ -32,6 +32,11 @@ sub check { is_deeply $body, $exp, $desc; } +sub failed_valid { + my ($tc) = @_; + qr/Validation failed for '\Q$tc\E'/; +} + my $o = Tikz->point(0); my $z = Tikz->point(1+2*i); @@ -55,6 +60,53 @@ check $l, 'a line from two Tikz points', <<'RES'; \draw (-1cm,2cm) -- (3cm,-4cm) ; RES +# Polyline + +my $w = Tikz->point(3, -4); + +for my $closed (0, 1) { + my $polyline = $closed ? 'closed_polyline' : 'polyline'; + my $cycle = $closed ? '-- cycle ' : ''; + my $desc = $closed ? 'closed polyline' : 'polyline'; + + my $pl = eval { + Tikz->$polyline($o, $z); + }; + is $@, '', "creating a $desc from two Tikz points doesn't croak"; + + check $pl, "a $desc from two Tikz points", <<"RES"; +\\draw (0cm,0cm) -- (1cm,2cm) $cycle; +RES + + $pl = eval { + Tikz->$polyline($o, $z, $w); + }; + is $@, '', "creating a $desc from three Tikz points doesn't croak"; + + check $pl, "a $desc from three Tikz points", <<"RES"; +\\draw (0cm,0cm) -- (1cm,2cm) -- (3cm,-4cm) $cycle; +RES + + $pl = eval { + Tikz->$polyline(-1, (2-3*i), [-4, 5]); + }; + is $@, '', "creating a $desc from three Tikz points doesn't croak"; + + check $pl, "a $desc from three Tikz points", <<"RES"; +\\draw (-1cm,0cm) -- (2cm,-3cm) -- (-4cm,5cm) $cycle; +RES + + $pl = eval { + Tikz->$polyline($o); + }; + like $@, qr/at least two LaTeX::TikZ::Set::Point objects are needed in order to build a polyline/, "creating a $desc from only one Tikz point croaks"; + + $pl = eval { + Tikz->$polyline(qw/foo bar/); + }; + like $@, failed_valid('LaTeX::TikZ::Point::Autocoerce'), "creating a $desc from two string croaks"; +} + # Rectangle my $r = eval {