6 use Test::More tests => 9 + 3 * 10;
11 use LaTeX::TikZ::TestHelper;
13 using Tikz->formatter(
18 my ($set, $desc, $exp, $layers) = @_;
20 local $Test::Builder::Level = $Test::Builder::Level + 1;
22 my ($head, $decl, $body) = check($set, $desc, $exp);
25 map("\\pgfdeclarelayer{$_}", @$layers),
26 "\\pgfsetlayers{main,@{[join ',', @$layers]}}",
29 is_deeply $decl, $exp_decl, "$desc: declarations";
33 Tikz->layer('middle');
35 is $@, '', 'creating a layer doesn\'t croak';
40 above => [ 'middle' ],
43 is $@, '', 'creating a layer above another doesn\'t croak';
49 below => [ 'middle' ],
52 is $@, '', 'creating a layer above and below anothers doesn\'t croak';
58 is $@, '', 'creating a layered raw set doesn\'t croak';
60 check_layers $foo, 'one layered raw set', <<'RES', [ 'middle' ];
61 \begin{pgfonlayer}{middle}
70 is $@, '', 'creating another layered raw set doesn\'t croak';
72 my $seq = Tikz->seq($foo, $bar);
74 check_layers $seq, 'a sequence of two layered raw sets',
75 <<'RES', [ qw<middle top> ];
76 \begin{pgfonlayer}{middle}
79 \begin{pgfonlayer}{top}
86 qr/Validation failed for '\Q$tc\E'/;
92 like $@, failed_valid('Str'), 'directly adding a wrong layer croaks';
97 is $@, '', 'directly adding a layer to a sequence doesn\'t croak';
102 is $@, '', 'calling an empty ->layer onto a sequence doesn\'t croak';
103 is "$res", "$seq", 'empty ->layer returns the object itself';
105 check_layers $seq, 'a layered sequence', <<'RES', [ qw<bottom middle top> ];
106 \begin{pgfonlayer}{bottom}
107 \begin{pgfonlayer}{middle}
110 \begin{pgfonlayer}{top}
116 my $baz = Tikz->raw('baz');
119 my $red = Tikz->color('red');
122 check_layers $seq, 'mods folding with layers 1',
123 <<'RES', [ qw<bottom middle top> ];
124 \begin{pgfonlayer}{bottom}
125 \begin{scope} [color=red]
126 \begin{pgfonlayer}{middle}
127 \draw [color=red] foo ;
129 \begin{pgfonlayer}{top}
130 \draw [color=red] bar ;
139 check_layers $seq, 'mods folding with layers 2',
140 <<'RES', [ qw<bottom middle top> ];
141 \begin{pgfonlayer}{bottom}
142 \begin{scope} [color=red]
143 \begin{pgfonlayer}{middle}
144 \draw [color=red] foo ;
146 \begin{pgfonlayer}{top}
147 \draw [color=red] bar ;
149 \begin{pgfonlayer}{top}
150 \draw [color=red] baz ;
156 my $seq2 = Tikz->seq($bar, $baz, $foo)
159 check_layers $seq2, 'mods folding with layers 3', <<'RES', [ qw<middle top> ];
160 \begin{scope} [color=red]
161 \begin{pgfonlayer}{top}
162 \begin{scope} [color=red]
167 \begin{pgfonlayer}{middle}
168 \draw [color=red] foo ;
173 my $qux = Tikz->raw('qux');
174 $seq2 = Tikz->seq($qux, $foo)
177 check_layers $seq2, 'mods folding with layers 4', <<'RES', [ 'middle' ];
178 \begin{scope} [color=red]
180 \begin{pgfonlayer}{middle}
181 \draw [color=red] foo ;
186 my $seq3 = Tikz->seq($seq2, $bar)
189 check_layers $seq3, 'mods folding with layers 5', <<'RES', [ qw<middle top> ];
190 \begin{scope} [color=red]
192 \begin{pgfonlayer}{middle}
193 \draw [color=red] foo ;
195 \begin{pgfonlayer}{top}
196 \draw [color=red] bar ;
201 $seq3 = Tikz->seq($bar, $seq2)
204 check_layers $seq3, 'mods folding with layers 6', <<'RES', [ qw<middle top> ];
205 \begin{scope} [color=red]
206 \begin{pgfonlayer}{top}
207 \draw [color=red] bar ;
210 \begin{pgfonlayer}{middle}
211 \draw [color=red] foo ;
216 my $blue = Tikz->color('blue');
219 check_layers $seq2, 'mods folding with layers 7', <<'RES', [ 'middle' ];
220 \begin{scope} [color=red]
221 \draw [color=blue] qux ;
222 \begin{pgfonlayer}{middle}
223 \draw [color=red] foo ;