]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - t/20-mod.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/LaTeX-TikZ.git] / t / 20-mod.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 23 + 2 * 24;
7
8 use LaTeX::TikZ;
9
10 use lib 't/lib';
11 use LaTeX::TikZ::TestHelper;
12
13 using Tikz->formatter(
14  format => '%d',
15 );
16
17 my $red = eval {
18  Tikz->color('red');
19 };
20 is $@, '', 'creating a color mod doesn\'t croak';
21
22 my $foo = eval {
23  Tikz->raw('foo')
24      ->mod($red)
25 };
26 is $@, '', 'creating a modded raw set doesn\'t croak';
27
28 check $foo, 'one modded raw set', <<'RES';
29 \draw [color=red] foo ;
30 RES
31
32 my $foo2 = eval {
33  Tikz->raw('foo')
34      ->mod('->')
35 };
36 is $@, '', 'creating a modded raw set from a string doesn\'t croak';
37
38 check $foo2, 'one modded raw set from a string', <<'RES';
39 \draw [->] foo ;
40 RES
41
42 sub failed_valid {
43  my ($tc) = @_;
44  qr/Validation failed for '\Q$tc\E'/;
45 }
46
47 eval {
48  Tikz->raw([ 'fail' ])
49      ->mod(Tikz->raw('epic'));
50 };
51 like $@, failed_valid('LaTeX::TikZ::Mod'), 'trying to use a non LTM mod croaks';
52
53 my $scale = eval {
54  Tikz->scale(2);
55 };
56 is $@, '', 'creating a scale mod doesn\'t croak';
57
58 $foo2 = eval {
59  Tikz->raw('foo')
60      ->mod($scale);
61 };
62 is $@, '', 'applying a scale mod doesn\'t croak';
63
64 check $foo2, 'a raw set with a scale mod', <<'RES';
65 \draw [scale=2.000] foo ;
66 RES
67
68 $foo2 = eval {
69  Tikz->union(
70   Tikz->raw('foo')
71       ->mod($scale),
72  )->mod(Tikz->scale(4));
73 };
74 is $@, '', 'applying two scale mods doesn\'t croak';
75
76 check $foo2, 'a union of a raw set with two scale mods', <<'RES';
77 \draw [scale=4.000] foo ;
78 RES
79
80 my $width = eval {
81  Tikz->width(25);
82 };
83 is $@, '', 'creating a width mod doesn\'t croak';
84
85 eval {
86  $foo->mod($width);
87 };
88 is $@, '', 'adding another mod doesn\'t croak';
89
90 check $foo, 'one double modded raw set', <<'RES';
91 \draw [color=red,line width=4.0pt] foo ;
92 RES
93
94 eval {
95  $foo->mod($red);
96 };
97 is $@, '', 're-adding an previously set mod doesn\'t croak';
98
99 check $foo, 'one triple modded raw set (with duplicates)', <<'RES';
100 \draw [color=red,line width=4.0pt] foo ;
101 RES
102
103 my $bar = Tikz->raw('bar');
104 $foo = eval {
105  Tikz->seq(
106   Tikz->raw('foo'),
107   $bar
108  )->mod($red, $width);
109 };
110 is $@, '', 'setting two mods in a row doesn\'t croak';
111
112 check $foo, 'one triple modded sequence of raw sets', <<'RES';
113 \begin{scope} [color=red,line width=4.0pt]
114 \draw foo ;
115 \draw bar ;
116 \end{scope}
117 RES
118
119 my $nested = eval {
120  Tikz->seq(
121   Tikz->seq(Tikz->raw("foo"))
122       ->mod($red)
123  )->mod($width)
124 };
125 is $@, '', 'creating nested modded sequences doesn\'t croak';
126
127 check $nested, 'nested modded sequences', <<'RES';
128 \draw [line width=4.0pt,color=red] foo ;
129 RES
130
131 my $baz = eval {
132  Tikz->raw('baz')
133      ->mod($red);
134 };
135 is $@, '', 'creating another colored raw set doesn\'t croak';
136
137 check Tikz->seq($foo, $baz), 'mods folding 1', <<'RES';
138 \begin{scope} [color=red]
139 \begin{scope} [line width=4.0pt]
140 \draw foo ;
141 \draw bar ;
142 \end{scope}
143 \draw baz ;
144 \end{scope}
145 RES
146
147 check Tikz->seq($baz, $foo), 'mods folding 2', <<'RES';
148 \begin{scope} [color=red]
149 \draw baz ;
150 \begin{scope} [line width=4.0pt]
151 \draw foo ;
152 \draw bar ;
153 \end{scope}
154 \end{scope}
155 RES
156
157 my $qux = eval {
158  Tikz->raw('qux')
159      ->mod($width);
160 };
161 is $@, '', 'creating another raw set with modded width doesn\'t croak';
162
163 check Tikz->seq($foo, $baz, $qux), 'mods folding 3', <<'RES';
164 \begin{scope} [color=red]
165 \begin{scope} [line width=4.0pt]
166 \draw foo ;
167 \draw bar ;
168 \end{scope}
169 \draw baz ;
170 \end{scope}
171 \draw [line width=4.0pt] qux ;
172 RES
173
174 check Tikz->seq($foo, $qux, $baz), 'mods folding 4', <<'RES';
175 \begin{scope} [line width=4.0pt]
176 \begin{scope} [color=red]
177 \draw foo ;
178 \draw bar ;
179 \end{scope}
180 \draw qux ;
181 \end{scope}
182 \draw [color=red] baz ;
183 RES
184
185 check Tikz->seq($baz, $foo, $qux), 'mods folding 5', <<'RES';
186 \begin{scope} [color=red]
187 \draw baz ;
188 \begin{scope} [line width=4.0pt]
189 \draw foo ;
190 \draw bar ;
191 \end{scope}
192 \end{scope}
193 \draw [line width=4.0pt] qux ;
194 RES
195
196 check Tikz->seq($baz, $qux, $foo), 'mods folding 6', <<'RES';
197 \draw [color=red] baz ;
198 \draw [line width=4.0pt] qux ;
199 \begin{scope} [color=red,line width=4.0pt]
200 \draw foo ;
201 \draw bar ;
202 \end{scope}
203 RES
204
205 check Tikz->seq($qux, $foo, $baz), 'mods folding 7', <<'RES';
206 \begin{scope} [line width=4.0pt]
207 \draw qux ;
208 \begin{scope} [color=red]
209 \draw foo ;
210 \draw bar ;
211 \end{scope}
212 \end{scope}
213 \draw [color=red] baz ;
214 RES
215
216 check Tikz->seq($qux, $baz, $foo), 'mods folding 8', <<'RES';
217 \draw [line width=4.0pt] qux ;
218 \draw [color=red] baz ;
219 \begin{scope} [color=red,line width=4.0pt]
220 \draw foo ;
221 \draw bar ;
222 \end{scope}
223 RES
224
225 my $seq = eval {
226  Tikz->seq($foo, $qux, $baz)
227      ->mod($red);
228 };
229 is $@, '', 'creating a modded sequence set doesn\'t croak';
230
231 check $seq, 'mod covering 1', <<'RES';
232 \begin{scope} [color=red]
233 \begin{scope} [line width=4.0pt]
234 \draw foo ;
235 \draw bar ;
236 \draw qux ;
237 \end{scope}
238 \draw baz ;
239 \end{scope}
240 RES
241
242 my $seq2 = eval {
243  Tikz->seq($seq, $qux)
244      ->mod(Tikz->color('blue'));
245 };
246 is $@, '', 'creating another modded sequence set doesn\'t croak';
247
248 check $seq2, 'mod covering 2', <<'RES';
249 \begin{scope} [color=blue]
250 \begin{scope} [color=red]
251 \begin{scope} [line width=4.0pt]
252 \draw foo ;
253 \draw bar ;
254 \draw qux ;
255 \end{scope}
256 \draw baz ;
257 \end{scope}
258 \draw [line width=4.0pt] qux ;
259 \end{scope}
260 RES
261
262 eval {
263  $foo->mod(Tikz->raw_mod('raw1'));
264  $seq->mod(Tikz->raw_mod('raw2'));
265 };
266 is $@, '', 'creating and adding raw mods doesn\'t croak';
267
268 check $seq, 'mod covering 3', <<'RES';
269 \begin{scope} [color=red,raw2]
270 \begin{scope} [line width=4.0pt]
271 \begin{scope} [raw1]
272 \draw foo ;
273 \draw bar ;
274 \end{scope}
275 \draw qux ;
276 \end{scope}
277 \draw baz ;
278 \end{scope}
279 RES
280
281 eval {
282  $baz->mod(Tikz->raw_mod($_)) for qw<raw2 raw3>;
283 };
284 is $@, '', 'creating and adding another raw mod doesn\'t croak';
285
286 check $seq, 'mod covering 4', <<'RES';
287 \begin{scope} [color=red,raw2]
288 \begin{scope} [line width=4.0pt]
289 \begin{scope} [raw1]
290 \draw foo ;
291 \draw bar ;
292 \end{scope}
293 \draw qux ;
294 \end{scope}
295 \draw [raw2,raw3] baz ;
296 \end{scope}
297 RES
298
299 eval {
300  $bar->mod(Tikz->width(50));
301 };
302 is $@, '', 'creating and adding another width mod doesn\'t croak';
303
304 check $seq, 'mod covering 5', <<'RES';
305 \begin{scope} [color=red,raw2]
306 \begin{scope} [line width=4.0pt]
307 \begin{scope} [raw1]
308 \draw foo ;
309 \draw [line width=8.0pt] bar ;
310 \end{scope}
311 \draw qux ;
312 \end{scope}
313 \draw [raw2,raw3] baz ;
314 \end{scope}
315 RES
316
317 my ($fred, $fblue) = eval {
318  map Tikz->fill($_), qw<red blue>;
319 };
320 is $@, '', 'creating two fill mods doesn\'t croak';
321
322 $seq = eval {
323  Tikz->seq(
324   Tikz->raw("foo")
325       ->mod($fred)
326  )->mod($fred);
327 };
328 is $@, '', 'creating a structure with two identical fill mods doesn\'t croak';
329
330 check $seq, 'mod covering 6', <<'RES';
331 \draw [fill=red] foo ;
332 RES
333
334 $seq = eval {
335  Tikz->seq(
336   Tikz->raw("foo")
337       ->mod($fblue)
338  )->mod($fred);
339 };
340 is $@, '', 'creating a structure with two different fill mods doesn\'t croak';
341
342 check $seq, 'mod covering 7', <<'RES';
343 \draw [fill=red,fill=blue] foo ;
344 RES
345
346 $seq = eval {
347  Tikz->seq(
348   Tikz->raw("foo")
349       ->mod($red)
350  )->mod($fred);
351 };
352 is $@, '', 'creating a structure with color and fill mods doesn\'t croak';
353
354 check $seq, 'mod covering 8', <<'RES';
355 \draw [fill=red,color=red] foo ;
356 RES