6 use Test::More tests => 13 + 2 * 17;
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]
92 is $@, '', 'creating another colored raw set doesn\'t croak';
94 check [ $foo, $baz ], 'mods folding 1', <<'RES';
95 \begin{scope} [color=red]
96 \begin{scope} [line width=4.0pt]
104 check [ $baz, $foo ], 'mods folding 2', <<'RES';
105 \begin{scope} [color=red]
107 \begin{scope} [line width=4.0pt]
118 is $@, '', 'creating another raw set with modded width doesn\'t croak';
120 check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES';
121 \begin{scope} [color=red]
122 \begin{scope} [line width=4.0pt]
128 \draw [line width=4.0pt] qux ;
131 check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES';
132 \begin{scope} [line width=4.0pt]
133 \begin{scope} [color=red]
139 \draw [color=red] baz ;
142 check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES';
143 \begin{scope} [color=red]
145 \begin{scope} [line width=4.0pt]
150 \draw [line width=4.0pt] qux ;
153 check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES';
154 \draw [color=red] baz ;
155 \draw [line width=4.0pt] qux ;
156 \begin{scope} [color=red,line width=4.0pt]
162 check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES';
163 \begin{scope} [line width=4.0pt]
165 \begin{scope} [color=red]
170 \draw [color=red] baz ;
173 check [ $qux, $baz, $foo ], 'mods folding 8', <<'RES';
174 \draw [line width=4.0pt] qux ;
175 \draw [color=red] baz ;
176 \begin{scope} [color=red,line width=4.0pt]
183 Tikz->seq($foo, $qux, $baz)
186 is $@, '', 'creating a modded sequence set doesn\'t croak';
188 check $seq, 'mod covering 1', <<'RES';
189 \begin{scope} [color=red]
190 \begin{scope} [line width=4.0pt]
200 Tikz->seq($seq, $qux)
201 ->mod(Tikz->color('blue'));
203 is $@, '', 'creating another modded sequence set doesn\'t croak';
205 check $seq2, 'mod covering 2', <<'RES';
206 \begin{scope} [color=blue]
207 \begin{scope} [color=red]
208 \begin{scope} [line width=4.0pt]
215 \draw [line width=4.0pt] qux ;
220 $foo->mod(Tikz->raw_mod('raw1'));
221 $seq->mod(Tikz->raw_mod('raw2'));
223 is $@, '', 'creating and adding raw mods doesn\'t croak';
225 check $seq, 'mod covering 3', <<'RES';
226 \begin{scope} [color=red,raw2]
227 \begin{scope} [line width=4.0pt]
239 $baz->mod(Tikz->raw_mod($_)) for qw/raw2 raw3/;
241 is $@, '', 'creating and adding another raw mod doesn\'t croak';
243 check $seq, 'mod covering 4', <<'RES';
244 \begin{scope} [color=red,raw2]
245 \begin{scope} [line width=4.0pt]
257 $bar->mod(Tikz->width(50));
259 is $@, '', 'creating and adding another width mod doesn\'t croak';
261 check $seq, 'mod covering 4', <<'RES';
262 \begin{scope} [color=red,raw2]
263 \begin{scope} [line width=4.0pt]
266 \draw [line width=8.0pt] bar ;