6 use Test::More tests => (16 + 2 * 5) + 2 * (13 + 2 * 3);
12 my $tikz = Tikz->formatter(
17 my ($set, $desc, $exp) = @_;
19 local $Test::Builder::Level = $Test::Builder::Level + 1;
21 my ($head, $decl, $body) = eval {
22 $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
24 is $@, '', "$desc: no error";
26 unless (ref $exp eq 'ARRAY') {
27 $exp = [ split /\n/, $exp ];
29 unshift @$exp, '\begin{tikzpicture}';
30 push @$exp, '\end{tikzpicture}';
32 is_deeply $body, $exp, $desc;
37 qr/Validation failed for '\Q$tc\E'/;
40 my $o = Tikz->point(0);
41 my $z = Tikz->point(1+2*i);
48 is $@, '', 'creating a line from two TikZ points doesn\'t croak';
50 check $l, 'a line from two Tikz points', <<'RES';
51 \draw (0cm,0cm) -- (1cm,2cm) ;
55 Tikz->line([-1,2] => 3-4*i);
57 is $@, '', 'creating a line from constants doesn\'t croak';
59 check $l, 'a line from two Tikz points', <<'RES';
60 \draw (-1cm,2cm) -- (3cm,-4cm) ;
68 is $@, '', 'creating an arrow from two points doesn\'t croak';
70 check $ar, 'an arrow from two points', <<'RES';
71 \draw [->] (0cm,0cm) -- (1cm,0cm) ;
75 Tikz->arrow(2, dir => -i());
77 is $@, '', 'creating an arrow from a point and a direction doesn\'t croak';
79 check $ar, 'an arrow from a point and a direction', <<'RES';
80 \draw [->] (2cm,0cm) -- (2cm,-1cm) ;
85 my $w = Tikz->point(3, -4);
87 for my $closed (0, 1) {
88 my $polyline = $closed ? 'closed_polyline' : 'polyline';
89 my $cycle = $closed ? '-- cycle ' : '';
90 my $desc = $closed ? 'closed polyline' : 'polyline';
93 Tikz->$polyline($o, $z);
95 is $@, '', "creating a $desc from two Tikz points doesn't croak";
97 check $pl, "a $desc from two Tikz points", <<"RES";
98 \\draw (0cm,0cm) -- (1cm,2cm) $cycle;
102 Tikz->$polyline($o, $z, $w);
104 is $@, '', "creating a $desc from three Tikz points doesn't croak";
106 check $pl, "a $desc from three Tikz points", <<"RES";
107 \\draw (0cm,0cm) -- (1cm,2cm) -- (3cm,-4cm) $cycle;
111 Tikz->$polyline(-1, (2-3*i), [-4, 5]);
113 is $@, '', "creating a $desc from three Tikz points doesn't croak";
115 check $pl, "a $desc from three Tikz points", <<"RES";
116 \\draw (-1cm,0cm) -- (2cm,-3cm) -- (-4cm,5cm) $cycle;
122 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";
125 Tikz->$polyline(qw/foo bar/);
127 like $@, failed_valid('LaTeX::TikZ::Point::Autocoerce'), "creating a $desc from two string croaks";
133 Tikz->rectangle($o => $z);
135 is $@, '', 'creating a rectangle from two TikZ points doesn\'t croak';
137 check $r, 'a rectangle from two Tikz points', <<'RES';
138 \draw (0cm,0cm) rectangle (1cm,2cm) ;
142 Tikz->rectangle([-1,2] => 3-4*i);
144 is $@, '', 'creating a rectangle from constants doesn\'t croak';
146 check $r, 'a rectangle from two Tikz points', <<'RES';
147 \draw (-1cm,2cm) rectangle (3cm,-4cm) ;
151 Tikz->rectangle($z => -3);
153 is $@, '', 'creating a rectangle from a TikZ point and a constant doesn\'t croak';
155 check $r, 'a rectangle from a TikZ point and a constant', <<'RES';
156 \draw (1cm,2cm) rectangle (-3cm,0cm) ;
160 Tikz->rectangle($o => { width => 3, height => -4 });
162 is $@, '', 'creating a rectangle from a TikZ point and width/height doesn\'t croak';
164 check $r, 'a rectangle from a TikZ point and width/height', <<'RES';
165 \draw (0cm,0cm) rectangle (3cm,-4cm) ;
169 Tikz->rectangle((-1+2*i) => { width => 3, height => -4 });
171 is $@, '', 'creating a rectangle from a constant and width/height doesn\'t croak';
173 check $r, 'a rectangle from a constant and width/height', <<'RES';
174 \draw (-1cm,2cm) rectangle (2cm,-2cm) ;
180 Tikz->circle($z => 3);
182 is $@, '', 'creating a circle from a TikZ point and a constant doesn\'t croak';
184 check $c, 'a circle from a Tikz point and a constant', <<'RES';
185 \draw (1cm,2cm) circle (3cm) ;
189 Tikz->circle([-1,2] => 3);
191 is $@, '', 'creating a circle from an array ref and a constant doesn\'t croak';
193 check $c, 'a circle from an array ref and a constant', <<'RES';
194 \draw (-1cm,2cm) circle (3cm) ;
198 Tikz->circle((4-5*i) => 3);
200 is $@, '', 'creating a circle from a complex and a constant doesn\'t croak';
202 check $c, 'a circle from a complex and a constant', <<'RES';
203 \draw (4cm,-5cm) circle (3cm) ;
207 Tikz->circle($o => -1);
209 like $@, failed_valid('__ANON__'),
210 'creating a circle with a negative radius croaks';
214 $tikz = Tikz->formatter(
221 is $@, '', 'creating a simple arc doesn\'t croak';
223 check $arc, 'simple arc', <<'RES';
225 \clip (0.969cm,0.000cm) -- (1.085cm,0.000cm) -- (1.032cm,0.335cm) -- (0.878cm,0.638cm) -- (0.638cm,0.878cm) -- (0.335cm,1.032cm) -- (0.000cm,1.085cm) -- (0.000cm,0.969cm) -- cycle ;
226 \draw (0.000cm,0.000cm) circle (1.000cm) ;
233 my $err = quotemeta 'Tikz->arc($first_point, $second_point, $center)';
234 like $@, qr/^$err/, 'creating an arc from only two points croaks';
239 like $@, qr/The two first points aren't on a circle of center the last/,
240 'creating an arc with two points not on a circle of center c croaks';