X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F11-point.t;h=4b31a503ea25690b0a0621aca3a31da1224b80d6;hb=0e7c2e9d009574e0d337db855d433a8e07d04512;hp=9e73f15c89b6d47ba2d578eb24525457eff7e721;hpb=19660696c832bcff26c87d371cccc4ffe118c782;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/t/11-point.t b/t/11-point.t index 9e73f15..4b31a50 100644 --- a/t/11-point.t +++ b/t/11-point.t @@ -3,35 +3,19 @@ use strict; use warnings; -use Test::More tests => 5 + 2 * 5; +use Test::More tests => 8 + 2 * 8 + 2 * (1 + 2 * 3); use Math::Complex; use LaTeX::TikZ; -my $tikz = Tikz->formatter( +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 $z = Math::Complex->make(1, 2); my $p = eval { @@ -52,6 +36,15 @@ check $p, 'a point from a constant Math::Complex object', <<'RES'; \draw (1cm,-2cm) ; RES +$p = eval { + Tikz->point; +}; +is $@, '', 'creating a point from nothing doesn\'t croak'; + +check $p, 'a point from nothing', <<'RES'; +\draw (0cm,0cm) ; +RES + $p = eval { Tikz->point(-7); }; @@ -78,3 +71,51 @@ is $@, '', 'creating a point from an array ref doesn\'t croak'; check $p, 'a point from an array ref', <<'RES'; \draw (-3cm,2cm) ; RES + +$p = eval { + Tikz->point( + [1,-1], + label => 'foo', + ); +}; +is $@, '', 'creating a labeled point from an array ref doesn\'t croak'; + +check $p, 'a labeled point', <<'RES'; +\draw (1cm,-1cm) [fill] circle (0.4pt) node[scale=0.20,above] {foo} ; +RES + +$p = eval { + Tikz->point( + [2,-2], + label => 'bar', + pos => 'below right', + ); +}; +is $@, '', + 'creating a labeled positioned point from an array ref doesn\'t croak'; + +check $p, 'a labeled positioned point', <<'RES'; +\draw (2cm,-2cm) [fill] circle (0.4pt) node[scale=0.20,below right] {bar} ; +RES + +my $union = eval { + Tikz->union( + Tikz->point([ 0, -1 ]), + Tikz->raw("foo"), + Tikz->point(9) + ); +}; +is $@, '', 'creating a simple union path doesn\'t croak'; +is_point_ok $union->begin, 0, -1, 'beginning of a simple union path'; +is_point_ok $union->end, 9, 0, 'end of a simple union path'; + +my $path = eval { + Tikz->union( + Tikz->join('--' => 1, 2, 3), + $union, + Tikz->chain(5 => '--' => [ 6, 1 ]), + ); +}; +is $@, '', 'creating a complex union path doesn\'t croak'; +is_point_ok $path->begin, 1, 0, 'beginning of a complex union path'; +is_point_ok $path->end, 6, 1, 'end of a complex union path';