6 use Test::More tests => 14 + 2 * 18;
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 ;
51 is $@, '', 'creating a width mod doesn\'t croak';
56 is $@, '', 'adding another mod doesn\'t croak';
58 check $foo, 'one double modded raw set', <<'RES';
59 \draw [color=red,line width=4.0pt] foo ;
65 is $@, '', 're-adding an previously set mod doesn\'t croak';
67 check $foo, 'one triple modded raw set (with duplicates)', <<'RES';
68 \draw [color=red,line width=4.0pt] foo ;
71 my $bar = Tikz->raw('bar');
78 is $@, '', 'setting two mods in a row doesn\'t croak';
80 check $foo, 'one triple modded sequence of raw sets', <<'RES';
81 \begin{scope} [color=red,line width=4.0pt]
89 Tikz->seq(Tikz->raw("foo"))
93 is $@, '', 'creating nested modded sequences doesn\'t croak';
95 check $nested, 'nested modded sequences', <<'RES';
96 \draw [line width=4.0pt,color=red] foo ;
103 is $@, '', 'creating another colored raw set doesn\'t croak';
105 check [ $foo, $baz ], 'mods folding 1', <<'RES';
106 \begin{scope} [color=red]
107 \begin{scope} [line width=4.0pt]
115 check [ $baz, $foo ], 'mods folding 2', <<'RES';
116 \begin{scope} [color=red]
118 \begin{scope} [line width=4.0pt]
129 is $@, '', 'creating another raw set with modded width doesn\'t croak';
131 check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES';
132 \begin{scope} [color=red]
133 \begin{scope} [line width=4.0pt]
139 \draw [line width=4.0pt] qux ;
142 check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES';
143 \begin{scope} [line width=4.0pt]
144 \begin{scope} [color=red]
150 \draw [color=red] baz ;
153 check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES';
154 \begin{scope} [color=red]
156 \begin{scope} [line width=4.0pt]
161 \draw [line width=4.0pt] qux ;
164 check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES';
165 \draw [color=red] baz ;
166 \draw [line width=4.0pt] qux ;
167 \begin{scope} [color=red,line width=4.0pt]
173 check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES';
174 \begin{scope} [line width=4.0pt]
176 \begin{scope} [color=red]
181 \draw [color=red] baz ;
184 check [ $qux, $baz, $foo ], 'mods folding 8', <<'RES';
185 \draw [line width=4.0pt] qux ;
186 \draw [color=red] baz ;
187 \begin{scope} [color=red,line width=4.0pt]
194 Tikz->seq($foo, $qux, $baz)
197 is $@, '', 'creating a modded sequence set doesn\'t croak';
199 check $seq, 'mod covering 1', <<'RES';
200 \begin{scope} [color=red]
201 \begin{scope} [line width=4.0pt]
211 Tikz->seq($seq, $qux)
212 ->mod(Tikz->color('blue'));
214 is $@, '', 'creating another modded sequence set doesn\'t croak';
216 check $seq2, 'mod covering 2', <<'RES';
217 \begin{scope} [color=blue]
218 \begin{scope} [color=red]
219 \begin{scope} [line width=4.0pt]
226 \draw [line width=4.0pt] qux ;
231 $foo->mod(Tikz->raw_mod('raw1'));
232 $seq->mod(Tikz->raw_mod('raw2'));
234 is $@, '', 'creating and adding raw mods doesn\'t croak';
236 check $seq, 'mod covering 3', <<'RES';
237 \begin{scope} [color=red,raw2]
238 \begin{scope} [line width=4.0pt]
250 $baz->mod(Tikz->raw_mod($_)) for qw/raw2 raw3/;
252 is $@, '', 'creating and adding another raw mod doesn\'t croak';
254 check $seq, 'mod covering 4', <<'RES';
255 \begin{scope} [color=red,raw2]
256 \begin{scope} [line width=4.0pt]
268 $bar->mod(Tikz->width(50));
270 is $@, '', 'creating and adding another width mod doesn\'t croak';
272 check $seq, 'mod covering 4', <<'RES';
273 \begin{scope} [color=red,raw2]
274 \begin{scope} [line width=4.0pt]
277 \draw [line width=8.0pt] bar ;