6 use Test::More tests => 14 + 2 * 18;
9 use LaTeX::TikZ::Formatter;
11 my $tikz = LaTeX::TikZ::Formatter->new(
16 my ($set, $desc, $exp) = @_;
18 local $Test::Builder::Level = $Test::Builder::Level + 1;
20 my ($head, $decl, $body) = eval {
21 $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
23 is $@, '', "$desc: no error";
25 unless (ref $exp eq 'ARRAY') {
26 $exp = [ split /\n/, $exp ];
28 unshift @$exp, '\begin{tikzpicture}';
29 push @$exp, '\end{tikzpicture}';
31 is_deeply $body, $exp, $desc;
37 is $@, '', 'creating a color mod doesn\'t croak';
43 is $@, '', 'creating a modded raw set doesn\'t croak';
45 check $foo, 'one modded raw set', <<'RES';
46 \draw [color=red] foo ;
52 is $@, '', 'creating a width mod doesn\'t croak';
57 is $@, '', 'adding another mod doesn\'t croak';
59 check $foo, 'one double modded raw set', <<'RES';
60 \draw [color=red,line width=4.0pt] foo ;
66 is $@, '', 're-adding an previously set mod doesn\'t croak';
68 check $foo, 'one triple modded raw set (with duplicates)', <<'RES';
69 \draw [color=red,line width=4.0pt] foo ;
72 my $bar = Tikz->raw('bar');
79 is $@, '', 'setting two mods in a row doesn\'t croak';
81 check $foo, 'one triple modded sequence of raw sets', <<'RES';
82 \begin{scope} [color=red,line width=4.0pt]
90 Tikz->seq(Tikz->raw("foo"))
94 is $@, '', 'creating nested modded sequences doesn\'t croak';
96 check $nested, 'nested modded sequences', <<'RES';
97 \draw [line width=4.0pt,color=red] foo ;
104 is $@, '', 'creating another colored raw set doesn\'t croak';
106 check [ $foo, $baz ], 'mods folding 1', <<'RES';
107 \begin{scope} [color=red]
108 \begin{scope} [line width=4.0pt]
116 check [ $baz, $foo ], 'mods folding 2', <<'RES';
117 \begin{scope} [color=red]
119 \begin{scope} [line width=4.0pt]
130 is $@, '', 'creating another raw set with modded width doesn\'t croak';
132 check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES';
133 \begin{scope} [color=red]
134 \begin{scope} [line width=4.0pt]
140 \draw [line width=4.0pt] qux ;
143 check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES';
144 \begin{scope} [line width=4.0pt]
145 \begin{scope} [color=red]
151 \draw [color=red] baz ;
154 check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES';
155 \begin{scope} [color=red]
157 \begin{scope} [line width=4.0pt]
162 \draw [line width=4.0pt] qux ;
165 check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES';
166 \draw [color=red] baz ;
167 \draw [line width=4.0pt] qux ;
168 \begin{scope} [color=red,line width=4.0pt]
174 check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES';
175 \begin{scope} [line width=4.0pt]
177 \begin{scope} [color=red]
182 \draw [color=red] baz ;
185 check [ $qux, $baz, $foo ], 'mods folding 8', <<'RES';
186 \draw [line width=4.0pt] qux ;
187 \draw [color=red] baz ;
188 \begin{scope} [color=red,line width=4.0pt]
195 Tikz->seq($foo, $qux, $baz)
198 is $@, '', 'creating a modded sequence set doesn\'t croak';
200 check $seq, 'mod covering 1', <<'RES';
201 \begin{scope} [color=red]
202 \begin{scope} [line width=4.0pt]
212 Tikz->seq($seq, $qux)
213 ->mod(Tikz->color('blue'));
215 is $@, '', 'creating another modded sequence set doesn\'t croak';
217 check $seq2, 'mod covering 2', <<'RES';
218 \begin{scope} [color=blue]
219 \begin{scope} [color=red]
220 \begin{scope} [line width=4.0pt]
227 \draw [line width=4.0pt] qux ;
232 $foo->mod(Tikz->raw_mod('raw1'));
233 $seq->mod(Tikz->raw_mod('raw2'));
235 is $@, '', 'creating and adding raw mods doesn\'t croak';
237 check $seq, 'mod covering 3', <<'RES';
238 \begin{scope} [color=red,raw2]
239 \begin{scope} [line width=4.0pt]
251 $baz->mod(Tikz->raw_mod($_)) for qw/raw2 raw3/;
253 is $@, '', 'creating and adding another raw mod doesn\'t croak';
255 check $seq, 'mod covering 4', <<'RES';
256 \begin{scope} [color=red,raw2]
257 \begin{scope} [line width=4.0pt]
269 $bar->mod(Tikz->width(50));
271 is $@, '', 'creating and adding another width mod doesn\'t croak';
273 check $seq, 'mod covering 4', <<'RES';
274 \begin{scope} [color=red,raw2]
275 \begin{scope} [line width=4.0pt]
278 \draw [line width=8.0pt] bar ;