6 use Test::More tests => (14 + 2 * 5) + 2 * (11 + 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) ;
65 my $w = Tikz->point(3, -4);
67 for my $closed (0, 1) {
68 my $polyline = $closed ? 'closed_polyline' : 'polyline';
69 my $cycle = $closed ? '-- cycle ' : '';
70 my $desc = $closed ? 'closed polyline' : 'polyline';
73 Tikz->$polyline($o, $z);
75 is $@, '', "creating a $desc from two Tikz points doesn't croak";
77 check $pl, "a $desc from two Tikz points", <<"RES";
78 \\draw (0cm,0cm) -- (1cm,2cm) $cycle;
82 Tikz->$polyline($o, $z, $w);
84 is $@, '', "creating a $desc from three Tikz points doesn't croak";
86 check $pl, "a $desc from three Tikz points", <<"RES";
87 \\draw (0cm,0cm) -- (1cm,2cm) -- (3cm,-4cm) $cycle;
91 Tikz->$polyline(-1, (2-3*i), [-4, 5]);
93 is $@, '', "creating a $desc from three Tikz points doesn't croak";
95 check $pl, "a $desc from three Tikz points", <<"RES";
96 \\draw (-1cm,0cm) -- (2cm,-3cm) -- (-4cm,5cm) $cycle;
102 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";
105 Tikz->$polyline(qw/foo bar/);
107 like $@, failed_valid('LaTeX::TikZ::Point::Autocoerce'), "creating a $desc from two string croaks";
113 Tikz->rectangle($o => $z);
115 is $@, '', 'creating a rectangle from two TikZ points doesn\'t croak';
117 check $r, 'a rectangle from two Tikz points', <<'RES';
118 \draw (0cm,0cm) rectangle (1cm,2cm) ;
122 Tikz->rectangle([-1,2] => 3-4*i);
124 is $@, '', 'creating a rectangle from constants doesn\'t croak';
126 check $r, 'a rectangle from two Tikz points', <<'RES';
127 \draw (-1cm,2cm) rectangle (3cm,-4cm) ;
131 Tikz->rectangle($z => -3);
133 is $@, '', 'creating a rectangle from a TikZ point and a constant doesn\'t croak';
135 check $r, 'a rectangle from a TikZ point and a constant', <<'RES';
136 \draw (1cm,2cm) rectangle (-3cm,0cm) ;
140 Tikz->rectangle($o => { width => 3, height => -4 });
142 is $@, '', 'creating a rectangle from a TikZ point and width/height doesn\'t croak';
144 check $r, 'a rectangle from a TikZ point and width/height', <<'RES';
145 \draw (0cm,0cm) rectangle (3cm,-4cm) ;
149 Tikz->rectangle((-1+2*i) => { width => 3, height => -4 });
151 is $@, '', 'creating a rectangle from a constant and width/height doesn\'t croak';
153 check $r, 'a rectangle from a constant and width/height', <<'RES';
154 \draw (-1cm,2cm) rectangle (2cm,-2cm) ;
160 Tikz->circle($z => 3);
162 is $@, '', 'creating a circle from a TikZ point and a constant doesn\'t croak';
164 check $c, 'a circle from a Tikz point and a constant', <<'RES';
165 \draw (1cm,2cm) circle (3cm) ;
169 Tikz->circle([-1,2] => 3);
171 is $@, '', 'creating a circle from an array ref and a constant doesn\'t croak';
173 check $c, 'a circle from an array ref and a constant', <<'RES';
174 \draw (-1cm,2cm) circle (3cm) ;
178 Tikz->circle((4-5*i) => 3);
180 is $@, '', 'creating a circle from a complex and a constant doesn\'t croak';
182 check $c, 'a circle from a complex and a constant', <<'RES';
183 \draw (4cm,-5cm) circle (3cm) ;
187 Tikz->circle($o => -1);
189 like $@, qr/isn't a non-negative real number/,
190 'creating a circle with a negative radius croaks';
194 $tikz = Tikz->formatter(
201 is $@, '', 'creating a simple arc doesn\'t croak';
203 check $arc, 'simple arc', <<'RES';
205 \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 ;
206 \draw (0.000cm,0.000cm) circle (1.000cm) ;
213 my $err = quotemeta 'Tikz->arc($first_point, $second_point, $center)';
214 like $@, qr/^$err/, 'creating an arc from only two points croaks';
219 like $@, qr/The two first points aren't on a circle of center the last/,
220 'creating an arc with two points not on a circle of center c croaks';