6 use Test::More tests => (16 + 2 * 5) + 2 * (13 + 2 * 3);
13 use LaTeX::TikZ::TestHelper;
15 using Tikz->formatter(
21 qr/Validation failed for '\Q$tc\E'/;
24 my $o = Tikz->point(0);
25 my $z = Tikz->point(1+2*i);
32 is $@, '', 'creating a line from two TikZ points doesn\'t croak';
34 check $l, 'a line from two Tikz points', <<'RES';
35 \draw (0cm,0cm) -- (1cm,2cm) ;
39 Tikz->line([-1,2] => 3-4*i);
41 is $@, '', 'creating a line from constants doesn\'t croak';
43 check $l, 'a line from two Tikz points', <<'RES';
44 \draw (-1cm,2cm) -- (3cm,-4cm) ;
52 is $@, '', 'creating an arrow from two points doesn\'t croak';
54 check $ar, 'an arrow from two points', <<'RES';
55 \draw [->] (0cm,0cm) -- (1cm,0cm) ;
59 Tikz->arrow(2, dir => -i());
61 is $@, '', 'creating an arrow from a point and a direction doesn\'t croak';
63 check $ar, 'an arrow from a point and a direction', <<'RES';
64 \draw [->] (2cm,0cm) -- (2cm,-1cm) ;
69 my $w = Tikz->point(3, -4);
71 for my $closed (0, 1) {
72 my $polyline = $closed ? 'closed_polyline' : 'polyline';
73 my $cycle = $closed ? '-- cycle ' : '';
74 my $desc = $closed ? 'closed polyline' : 'polyline';
77 Tikz->$polyline($o, $z);
79 is $@, '', "creating a $desc from two Tikz points doesn't croak";
81 check $pl, "a $desc from two Tikz points", <<"RES";
82 \\draw (0cm,0cm) -- (1cm,2cm) $cycle;
86 Tikz->$polyline($o, $z, $w);
88 is $@, '', "creating a $desc from three Tikz points doesn't croak";
90 check $pl, "a $desc from three Tikz points", <<"RES";
91 \\draw (0cm,0cm) -- (1cm,2cm) -- (3cm,-4cm) $cycle;
95 Tikz->$polyline(-1, (2-3*i), [-4, 5]);
97 is $@, '', "creating a $desc from three Tikz points doesn't croak";
99 check $pl, "a $desc from three Tikz points", <<"RES";
100 \\draw (-1cm,0cm) -- (2cm,-3cm) -- (-4cm,5cm) $cycle;
106 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";
109 Tikz->$polyline(qw/foo bar/);
111 like $@, failed_valid('LaTeX::TikZ::Point::Autocoerce'), "creating a $desc from two string croaks";
117 Tikz->rectangle($o => $z);
119 is $@, '', 'creating a rectangle from two TikZ points doesn\'t croak';
121 check $r, 'a rectangle from two Tikz points', <<'RES';
122 \draw (0cm,0cm) rectangle (1cm,2cm) ;
126 Tikz->rectangle([-1,2] => 3-4*i);
128 is $@, '', 'creating a rectangle from constants doesn\'t croak';
130 check $r, 'a rectangle from two Tikz points', <<'RES';
131 \draw (-1cm,2cm) rectangle (3cm,-4cm) ;
135 Tikz->rectangle($z => -3);
137 is $@, '', 'creating a rectangle from a TikZ point and a constant doesn\'t croak';
139 check $r, 'a rectangle from a TikZ point and a constant', <<'RES';
140 \draw (1cm,2cm) rectangle (-3cm,0cm) ;
144 Tikz->rectangle($o => { width => 3, height => -4 });
146 is $@, '', 'creating a rectangle from a TikZ point and width/height doesn\'t croak';
148 check $r, 'a rectangle from a TikZ point and width/height', <<'RES';
149 \draw (0cm,0cm) rectangle (3cm,-4cm) ;
153 Tikz->rectangle((-1+2*i) => { width => 3, height => -4 });
155 is $@, '', 'creating a rectangle from a constant and width/height doesn\'t croak';
157 check $r, 'a rectangle from a constant and width/height', <<'RES';
158 \draw (-1cm,2cm) rectangle (2cm,-2cm) ;
164 Tikz->circle($z => 3);
166 is $@, '', 'creating a circle from a TikZ point and a constant doesn\'t croak';
168 check $c, 'a circle from a Tikz point and a constant', <<'RES';
169 \draw (1cm,2cm) circle (3cm) ;
173 Tikz->circle([-1,2] => 3);
175 is $@, '', 'creating a circle from an array ref and a constant doesn\'t croak';
177 check $c, 'a circle from an array ref and a constant', <<'RES';
178 \draw (-1cm,2cm) circle (3cm) ;
182 Tikz->circle((4-5*i) => 3);
184 is $@, '', 'creating a circle from a complex and a constant doesn\'t croak';
186 check $c, 'a circle from a complex and a constant', <<'RES';
187 \draw (4cm,-5cm) circle (3cm) ;
191 Tikz->circle($o => -1);
193 like $@, failed_valid('__ANON__'),
194 'creating a circle with a negative radius croaks';
198 using Tikz->formatter(
205 is $@, '', 'creating a simple arc doesn\'t croak';
207 check $arc, 'simple arc', <<'RES';
209 \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 ;
210 \draw (0.000cm,0.000cm) circle (1.000cm) ;
217 my $err = quotemeta 'Tikz->arc($first_point, $second_point, $center)';
218 like $@, qr/^$err/, 'creating an arc from only two points croaks';
223 like $@, qr/The two first points aren't on a circle of center the last/,
224 'creating an arc with two points not on a circle of center c croaks';