6 use Test::More tests => 20 + 2 * 22;
10 my $tikz = Tikz->formatter(
15 my ($set, $desc, $exp) = @_;
17 local $Test::Builder::Level = $Test::Builder::Level + 1;
19 my ($head, $decl, $body) = eval {
20 $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
22 is $@, '', "$desc: no error";
24 unless (ref $exp eq 'ARRAY') {
25 $exp = [ split /\n/, $exp ];
27 unshift @$exp, '\begin{tikzpicture}';
28 push @$exp, '\end{tikzpicture}';
30 is_deeply $body, $exp, $desc;
36 is $@, '', 'creating a color mod doesn\'t croak';
42 is $@, '', 'creating a modded raw set doesn\'t croak';
44 check $foo, 'one modded raw set', <<'RES';
45 \draw [color=red] foo ;
52 is $@, '', 'creating a modded raw set from a string doesn\'t croak';
54 check $foo2, 'one modded raw set from a string', <<'RES';
60 qr/Validation failed for '\Q$tc\E'/;
65 ->mod(Tikz->raw('epic'));
67 like $@, failed_valid('LaTeX::TikZ::Mod'), 'trying to use a non LTM mod croaks';
72 is $@, '', 'creating a width mod doesn\'t croak';
77 is $@, '', 'adding another mod doesn\'t croak';
79 check $foo, 'one double modded raw set', <<'RES';
80 \draw [color=red,line width=4.0pt] foo ;
86 is $@, '', 're-adding an previously set mod doesn\'t croak';
88 check $foo, 'one triple modded raw set (with duplicates)', <<'RES';
89 \draw [color=red,line width=4.0pt] foo ;
92 my $bar = Tikz->raw('bar');
99 is $@, '', 'setting two mods in a row doesn\'t croak';
101 check $foo, 'one triple modded sequence of raw sets', <<'RES';
102 \begin{scope} [color=red,line width=4.0pt]
110 Tikz->seq(Tikz->raw("foo"))
114 is $@, '', 'creating nested modded sequences doesn\'t croak';
116 check $nested, 'nested modded sequences', <<'RES';
117 \draw [line width=4.0pt,color=red] foo ;
124 is $@, '', 'creating another colored raw set doesn\'t croak';
126 check Tikz->seq($foo, $baz), 'mods folding 1', <<'RES';
127 \begin{scope} [color=red]
128 \begin{scope} [line width=4.0pt]
136 check Tikz->seq($baz, $foo), 'mods folding 2', <<'RES';
137 \begin{scope} [color=red]
139 \begin{scope} [line width=4.0pt]
150 is $@, '', 'creating another raw set with modded width doesn\'t croak';
152 check Tikz->seq($foo, $baz, $qux), 'mods folding 3', <<'RES';
153 \begin{scope} [color=red]
154 \begin{scope} [line width=4.0pt]
160 \draw [line width=4.0pt] qux ;
163 check Tikz->seq($foo, $qux, $baz), 'mods folding 4', <<'RES';
164 \begin{scope} [line width=4.0pt]
165 \begin{scope} [color=red]
171 \draw [color=red] baz ;
174 check Tikz->seq($baz, $foo, $qux), 'mods folding 5', <<'RES';
175 \begin{scope} [color=red]
177 \begin{scope} [line width=4.0pt]
182 \draw [line width=4.0pt] qux ;
185 check Tikz->seq($baz, $qux, $foo), 'mods folding 6', <<'RES';
186 \draw [color=red] baz ;
187 \draw [line width=4.0pt] qux ;
188 \begin{scope} [color=red,line width=4.0pt]
194 check Tikz->seq($qux, $foo, $baz), 'mods folding 7', <<'RES';
195 \begin{scope} [line width=4.0pt]
197 \begin{scope} [color=red]
202 \draw [color=red] baz ;
205 check Tikz->seq($qux, $baz, $foo), 'mods folding 8', <<'RES';
206 \draw [line width=4.0pt] qux ;
207 \draw [color=red] baz ;
208 \begin{scope} [color=red,line width=4.0pt]
215 Tikz->seq($foo, $qux, $baz)
218 is $@, '', 'creating a modded sequence set doesn\'t croak';
220 check $seq, 'mod covering 1', <<'RES';
221 \begin{scope} [color=red]
222 \begin{scope} [line width=4.0pt]
232 Tikz->seq($seq, $qux)
233 ->mod(Tikz->color('blue'));
235 is $@, '', 'creating another modded sequence set doesn\'t croak';
237 check $seq2, 'mod covering 2', <<'RES';
238 \begin{scope} [color=blue]
239 \begin{scope} [color=red]
240 \begin{scope} [line width=4.0pt]
247 \draw [line width=4.0pt] qux ;
252 $foo->mod(Tikz->raw_mod('raw1'));
253 $seq->mod(Tikz->raw_mod('raw2'));
255 is $@, '', 'creating and adding raw mods doesn\'t croak';
257 check $seq, 'mod covering 3', <<'RES';
258 \begin{scope} [color=red,raw2]
259 \begin{scope} [line width=4.0pt]
271 $baz->mod(Tikz->raw_mod($_)) for qw/raw2 raw3/;
273 is $@, '', 'creating and adding another raw mod doesn\'t croak';
275 check $seq, 'mod covering 4', <<'RES';
276 \begin{scope} [color=red,raw2]
277 \begin{scope} [line width=4.0pt]
289 $bar->mod(Tikz->width(50));
291 is $@, '', 'creating and adding another width mod doesn\'t croak';
293 check $seq, 'mod covering 5', <<'RES';
294 \begin{scope} [color=red,raw2]
295 \begin{scope} [line width=4.0pt]
298 \draw [line width=8.0pt] bar ;
306 my ($fred, $fblue) = eval {
307 map Tikz->fill($_), qw/red blue/;
309 is $@, '', 'creating two fill mods doesn\'t croak';
317 is $@, '', 'creating a structure with two identical fill mods doesn\'t croak';
319 check $seq, 'mod covering 6', <<'RES';
320 \draw [fill=red] foo ;
329 is $@, '', 'creating a structure with two different fill mods doesn\'t croak';
331 check $seq, 'mod covering 7', <<'RES';
332 \draw [fill=red,fill=blue] foo ;
341 is $@, '', 'creating a structure with color and fill mods doesn\'t croak';
343 check $seq, 'mod covering 8', <<'RES';
344 \draw [fill=red,color=red] foo ;