6 use Test::More tests => 11 + 2 * 10;
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;
35 my $o = Tikz->point(0);
36 my $z = Tikz->point(1+2*i);
43 is $@, '', 'creating a line from two TikZ points doesn\'t croak';
45 check $l, 'a line from two Tikz points', <<'RES';
46 \draw (0cm,0cm) -- (1cm,2cm) ;
50 Tikz->line([-1,2] => 3-4*i);
52 is $@, '', 'creating a line from constants doesn\'t croak';
54 check $l, 'a line from two Tikz points', <<'RES';
55 \draw (-1cm,2cm) -- (3cm,-4cm) ;
61 Tikz->rectangle($o => $z);
63 is $@, '', 'creating a rectangle from two TikZ points doesn\'t croak';
65 check $r, 'a rectangle from two Tikz points', <<'RES';
66 \draw (0cm,0cm) rectangle (1cm,2cm) ;
70 Tikz->rectangle([-1,2] => 3-4*i);
72 is $@, '', 'creating a rectangle from constants doesn\'t croak';
74 check $r, 'a rectangle from two Tikz points', <<'RES';
75 \draw (-1cm,2cm) rectangle (3cm,-4cm) ;
79 Tikz->rectangle($z => -3);
81 is $@, '', 'creating a rectangle from a TikZ point and a constant doesn\'t croak';
83 check $r, 'a rectangle from a TikZ point and a constant', <<'RES';
84 \draw (1cm,2cm) rectangle (-3cm,0cm) ;
88 Tikz->rectangle($o => { width => 3, height => -4 });
90 is $@, '', 'creating a rectangle from a TikZ point and width/height doesn\'t croak';
92 check $r, 'a rectangle from a TikZ point and width/height', <<'RES';
93 \draw (0cm,0cm) rectangle (3cm,-4cm) ;
97 Tikz->rectangle((-1+2*i) => { width => 3, height => -4 });
99 is $@, '', 'creating a rectangle from a constant and width/height doesn\'t croak';
101 check $r, 'a rectangle from a constant and width/height', <<'RES';
102 \draw (-1cm,2cm) rectangle (2cm,-2cm) ;
108 Tikz->circle($z => 3);
110 is $@, '', 'creating a circle from a TikZ point and a constant doesn\'t croak';
112 check $c, 'a circle from a Tikz point and a constant', <<'RES';
113 \draw (1cm,2cm) circle (3cm) ;
117 Tikz->circle([-1,2] => 3);
119 is $@, '', 'creating a circle from an array ref and a constant doesn\'t croak';
121 check $c, 'a circle from an array ref and a constant', <<'RES';
122 \draw (-1cm,2cm) circle (3cm) ;
126 Tikz->circle((4-5*i) => 3);
128 is $@, '', 'creating a circle from a complex and a constant doesn\'t croak';
130 check $c, 'a circle from a complex and a constant', <<'RES';
131 \draw (4cm,-5cm) circle (3cm) ;
135 Tikz->circle($o => -1);
137 like $@, qr/isn't a non-negative real number/,
138 'creating a circle with a negative radius croaks';