]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - t/20-mod.t
Switch to qw<>
[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 => 20 + 2 * 22;
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 $width = eval {
54  Tikz->width(25);
55 };
56 is $@, '', 'creating a width mod doesn\'t croak';
57
58 eval {
59  $foo->mod($width);
60 };
61 is $@, '', 'adding another mod doesn\'t croak';
62
63 check $foo, 'one double modded raw set', <<'RES';
64 \draw [color=red,line width=4.0pt] foo ;
65 RES
66
67 eval {
68  $foo->mod($red);
69 };
70 is $@, '', 're-adding an previously set mod doesn\'t croak';
71
72 check $foo, 'one triple modded raw set (with duplicates)', <<'RES';
73 \draw [color=red,line width=4.0pt] foo ;
74 RES
75
76 my $bar = Tikz->raw('bar');
77 $foo = eval {
78  Tikz->seq(
79   Tikz->raw('foo'),
80   $bar
81  )->mod($red, $width);
82 };
83 is $@, '', 'setting two mods in a row doesn\'t croak';
84
85 check $foo, 'one triple modded sequence of raw sets', <<'RES';
86 \begin{scope} [color=red,line width=4.0pt]
87 \draw foo ;
88 \draw bar ;
89 \end{scope}
90 RES
91
92 my $nested = eval {
93  Tikz->seq(
94   Tikz->seq(Tikz->raw("foo"))
95       ->mod($red)
96  )->mod($width)
97 };
98 is $@, '', 'creating nested modded sequences doesn\'t croak';
99
100 check $nested, 'nested modded sequences', <<'RES';
101 \draw [line width=4.0pt,color=red] foo ;
102 RES
103
104 my $baz = eval {
105  Tikz->raw('baz')
106      ->mod($red);
107 };
108 is $@, '', 'creating another colored raw set doesn\'t croak';
109
110 check Tikz->seq($foo, $baz), 'mods folding 1', <<'RES';
111 \begin{scope} [color=red]
112 \begin{scope} [line width=4.0pt]
113 \draw foo ;
114 \draw bar ;
115 \end{scope}
116 \draw baz ;
117 \end{scope}
118 RES
119
120 check Tikz->seq($baz, $foo), 'mods folding 2', <<'RES';
121 \begin{scope} [color=red]
122 \draw baz ;
123 \begin{scope} [line width=4.0pt]
124 \draw foo ;
125 \draw bar ;
126 \end{scope}
127 \end{scope}
128 RES
129
130 my $qux = eval {
131  Tikz->raw('qux')
132      ->mod($width);
133 };
134 is $@, '', 'creating another raw set with modded width doesn\'t croak';
135
136 check Tikz->seq($foo, $baz, $qux), 'mods folding 3', <<'RES';
137 \begin{scope} [color=red]
138 \begin{scope} [line width=4.0pt]
139 \draw foo ;
140 \draw bar ;
141 \end{scope}
142 \draw baz ;
143 \end{scope}
144 \draw [line width=4.0pt] qux ;
145 RES
146
147 check Tikz->seq($foo, $qux, $baz), 'mods folding 4', <<'RES';
148 \begin{scope} [line width=4.0pt]
149 \begin{scope} [color=red]
150 \draw foo ;
151 \draw bar ;
152 \end{scope}
153 \draw qux ;
154 \end{scope}
155 \draw [color=red] baz ;
156 RES
157
158 check Tikz->seq($baz, $foo, $qux), 'mods folding 5', <<'RES';
159 \begin{scope} [color=red]
160 \draw baz ;
161 \begin{scope} [line width=4.0pt]
162 \draw foo ;
163 \draw bar ;
164 \end{scope}
165 \end{scope}
166 \draw [line width=4.0pt] qux ;
167 RES
168
169 check Tikz->seq($baz, $qux, $foo), 'mods folding 6', <<'RES';
170 \draw [color=red] baz ;
171 \draw [line width=4.0pt] qux ;
172 \begin{scope} [color=red,line width=4.0pt]
173 \draw foo ;
174 \draw bar ;
175 \end{scope}
176 RES
177
178 check Tikz->seq($qux, $foo, $baz), 'mods folding 7', <<'RES';
179 \begin{scope} [line width=4.0pt]
180 \draw qux ;
181 \begin{scope} [color=red]
182 \draw foo ;
183 \draw bar ;
184 \end{scope}
185 \end{scope}
186 \draw [color=red] baz ;
187 RES
188
189 check Tikz->seq($qux, $baz, $foo), 'mods folding 8', <<'RES';
190 \draw [line width=4.0pt] qux ;
191 \draw [color=red] baz ;
192 \begin{scope} [color=red,line width=4.0pt]
193 \draw foo ;
194 \draw bar ;
195 \end{scope}
196 RES
197
198 my $seq = eval {
199  Tikz->seq($foo, $qux, $baz)
200      ->mod($red);
201 };
202 is $@, '', 'creating a modded sequence set doesn\'t croak';
203
204 check $seq, 'mod covering 1', <<'RES';
205 \begin{scope} [color=red]
206 \begin{scope} [line width=4.0pt]
207 \draw foo ;
208 \draw bar ;
209 \draw qux ;
210 \end{scope}
211 \draw baz ;
212 \end{scope}
213 RES
214
215 my $seq2 = eval {
216  Tikz->seq($seq, $qux)
217      ->mod(Tikz->color('blue'));
218 };
219 is $@, '', 'creating another modded sequence set doesn\'t croak';
220
221 check $seq2, 'mod covering 2', <<'RES';
222 \begin{scope} [color=blue]
223 \begin{scope} [color=red]
224 \begin{scope} [line width=4.0pt]
225 \draw foo ;
226 \draw bar ;
227 \draw qux ;
228 \end{scope}
229 \draw baz ;
230 \end{scope}
231 \draw [line width=4.0pt] qux ;
232 \end{scope}
233 RES
234
235 eval {
236  $foo->mod(Tikz->raw_mod('raw1'));
237  $seq->mod(Tikz->raw_mod('raw2'));
238 };
239 is $@, '', 'creating and adding raw mods doesn\'t croak';
240
241 check $seq, 'mod covering 3', <<'RES';
242 \begin{scope} [color=red,raw2]
243 \begin{scope} [line width=4.0pt]
244 \begin{scope} [raw1]
245 \draw foo ;
246 \draw bar ;
247 \end{scope}
248 \draw qux ;
249 \end{scope}
250 \draw baz ;
251 \end{scope}
252 RES
253
254 eval {
255  $baz->mod(Tikz->raw_mod($_)) for qw<raw2 raw3>;
256 };
257 is $@, '', 'creating and adding another raw mod doesn\'t croak';
258
259 check $seq, 'mod covering 4', <<'RES';
260 \begin{scope} [color=red,raw2]
261 \begin{scope} [line width=4.0pt]
262 \begin{scope} [raw1]
263 \draw foo ;
264 \draw bar ;
265 \end{scope}
266 \draw qux ;
267 \end{scope}
268 \draw [raw2,raw3] baz ;
269 \end{scope}
270 RES
271
272 eval {
273  $bar->mod(Tikz->width(50));
274 };
275 is $@, '', 'creating and adding another width mod doesn\'t croak';
276
277 check $seq, 'mod covering 5', <<'RES';
278 \begin{scope} [color=red,raw2]
279 \begin{scope} [line width=4.0pt]
280 \begin{scope} [raw1]
281 \draw foo ;
282 \draw [line width=8.0pt] bar ;
283 \end{scope}
284 \draw qux ;
285 \end{scope}
286 \draw [raw2,raw3] baz ;
287 \end{scope}
288 RES
289
290 my ($fred, $fblue) = eval {
291  map Tikz->fill($_), qw<red blue>;
292 };
293 is $@, '', 'creating two fill mods doesn\'t croak';
294
295 $seq = eval {
296  Tikz->seq(
297   Tikz->raw("foo")
298       ->mod($fred)
299  )->mod($fred);
300 };
301 is $@, '', 'creating a structure with two identical fill mods doesn\'t croak';
302
303 check $seq, 'mod covering 6', <<'RES';
304 \draw [fill=red] foo ;
305 RES
306
307 $seq = eval {
308  Tikz->seq(
309   Tikz->raw("foo")
310       ->mod($fblue)
311  )->mod($fred);
312 };
313 is $@, '', 'creating a structure with two different fill mods doesn\'t croak';
314
315 check $seq, 'mod covering 7', <<'RES';
316 \draw [fill=red,fill=blue] foo ;
317 RES
318
319 $seq = eval {
320  Tikz->seq(
321   Tikz->raw("foo")
322       ->mod($red)
323  )->mod($fred);
324 };
325 is $@, '', 'creating a structure with color and fill mods doesn\'t croak';
326
327 check $seq, 'mod covering 8', <<'RES';
328 \draw [fill=red,color=red] foo ;
329 RES