6 use Test::More tests => 19 + 2 * 20;
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');
76 is $@, '', 'appending to a modded set doesn\'t croak';
78 check $foo, 'one triple modded sequence of raw sets (with duplicates)', <<'RES';
79 \begin{scope} [color=red,line width=4.0pt]
85 my $set = Tikz->raw('wut');
90 is $@, '', 'calling empty mod out of a set doesn\'t croak';
91 is "$set_mod", "$set", 'calling empty mod out of a set returns the set';
94 $set->mod(Tikz->raw_mod('raw1'));
97 'creating and applying a raw mod on a set in scalar context doesn\'t croak';
98 is ref($new), 'LaTeX::TikZ::Set::Mod', 'new set is of the right kind';
99 isnt "$new", "$set", 'new set is different from the old one';
101 check $set, '', <<'RES';
105 check $new, '', <<'RES';
110 $set->mod(Tikz->raw_mod('raw2'));
114 'creating and applying a raw mod on a set in void context doesn\'t croak';
115 is ref($new), 'LaTeX::TikZ::Set::Mod', 'new set is of the right kind';
117 check $set, '', <<'RES';
121 check $new, '', <<'RES';
129 is $@, '', 'creating another colored raw set doesn\'t croak';
131 check [ $foo, $baz ], 'mods folding 1', <<'RES';
132 \begin{scope} [color=red]
133 \begin{scope} [line width=4.0pt]
141 check [ $baz, $foo ], 'mods folding 2', <<'RES';
142 \begin{scope} [color=red]
144 \begin{scope} [line width=4.0pt]
155 is $@, '', 'creating another raw set with modded width doesn\'t croak';
157 check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES';
158 \begin{scope} [color=red]
159 \begin{scope} [line width=4.0pt]
165 \draw [line width=4.0pt] qux ;
168 check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES';
169 \begin{scope} [line width=4.0pt]
170 \begin{scope} [color=red]
176 \draw [color=red] baz ;
179 check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES';
180 \begin{scope} [color=red]
182 \begin{scope} [line width=4.0pt]
187 \draw [line width=4.0pt] qux ;
190 check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES';
191 \draw [color=red] baz ;
192 \draw [line width=4.0pt] qux ;
193 \begin{scope} [color=red,line width=4.0pt]
199 check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES';
200 \begin{scope} [line width=4.0pt]
202 \begin{scope} [color=red]
207 \draw [color=red] baz ;
210 check [ $qux, $baz, $foo ], 'mods folding 8', <<'RES';
211 \draw [line width=4.0pt] qux ;
212 \draw [color=red] baz ;
213 \begin{scope} [color=red,line width=4.0pt]
220 Tikz->seq($foo, $qux, $baz)
223 is $@, '', 'creating a modded sequence set doesn\'t croak';
225 check $seq, 'mod covering 1', <<'RES';
226 \begin{scope} [color=red]
227 \begin{scope} [line width=4.0pt]
237 Tikz->seq($seq, $qux)
238 ->mod(Tikz->color('blue'));
240 is $@, '', 'creating another modded sequence set doesn\'t croak';
242 check $seq2, 'mod covering 2', <<'RES';
243 \begin{scope} [color=blue]
244 \begin{scope} [color=red]
245 \begin{scope} [line width=4.0pt]
252 \draw [line width=4.0pt] qux ;
257 $foo->mod(Tikz->raw_mod('raw1'));
258 $seq->mod(Tikz->raw_mod('raw2'));
260 is $@, '', 'creating and adding raw mods doesn\'t croak';
262 check $seq, 'mod covering 3', <<'RES';
263 \begin{scope} [color=red,raw2]
264 \begin{scope} [line width=4.0pt]
276 $baz->mod(Tikz->raw_mod($_)) for qw/raw2 raw3/;
278 is $@, '', 'creating and adding another raw mod doesn\'t croak';
280 check $seq, 'mod covering 4', <<'RES';
281 \begin{scope} [color=red,raw2]
282 \begin{scope} [line width=4.0pt]