]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - t/21-layer.t
Factor the check() test function in an helper test module
[perl/modules/LaTeX-TikZ.git] / t / 21-layer.t
index 1087d5cae03b2dca912628860851f1fcedde9bea..a4990b50e41a81e8631e955a82bd2a78815a8ee7 100644 (file)
@@ -7,25 +7,19 @@ use Test::More tests => 9 + 3 * 10;
 
 use LaTeX::TikZ;
 
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
  format => '%d',
 );
 
-sub check {
+sub check_layers {
  my ($set, $desc, $exp, $layers) = @_;
 
  local $Test::Builder::Level = $Test::Builder::Level + 1;
 
- my ($head, $decl, $body) = eval {
-  $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
- };
- is $@, '', "$desc: no error";
-
- unless (ref $exp eq 'ARRAY') {
-  $exp = [ split /\n/, $exp ];
- }
- unshift @$exp, '\begin{tikzpicture}';
- push    @$exp, '\end{tikzpicture}';
+ my ($head, $decl, $body) = check($set, $desc, $exp);
 
  my $exp_decl = [
   map("\\pgfdeclarelayer{$_}", @$layers),
@@ -33,7 +27,6 @@ sub check {
  ];
 
  is_deeply $decl, $exp_decl, "$desc: declarations";
- is_deeply $body, $exp,      "$desc: body";
 }
 
 my $middle = eval {
@@ -64,7 +57,7 @@ my $foo = eval {
 };
 is $@, '', 'creating a layered raw set doesn\'t croak';
 
-check $foo, 'one layered raw set', <<'RES', [ 'middle' ];
+check_layers $foo, 'one layered raw set', <<'RES', [ 'middle' ];
 \begin{pgfonlayer}{middle}
 \draw foo ;
 \end{pgfonlayer}
@@ -78,7 +71,8 @@ is $@, '', 'creating another layered raw set doesn\'t croak';
 
 my $seq = Tikz->seq($foo, $bar);
 
-check $seq, 'a sequence of two layered raw sets', <<'RES', [ qw/middle top/ ];
+check_layers $seq, 'a sequence of two layered raw sets',
+             <<'RES', [ qw/middle top/ ];
 \begin{pgfonlayer}{middle}
 \draw foo ;
 \end{pgfonlayer}
@@ -108,7 +102,7 @@ my $res = eval {
 is $@,     '',     'calling an empty ->layer onto a sequence doesn\'t croak';
 is "$res", "$seq", 'empty ->layer returns the object itself';
 
-check $seq, 'a layered sequence', <<'RES', [ qw/bottom middle top/ ];
+check_layers $seq, 'a layered sequence', <<'RES', [ qw/bottom middle top/ ];
 \begin{pgfonlayer}{bottom}
 \begin{pgfonlayer}{middle}
 \draw foo ;
@@ -125,7 +119,8 @@ $seq->add($baz);
 my $red = Tikz->color('red');
 $seq->mod($red);
 
-check $seq, 'mods folding with layers 1', <<'RES', [ qw/bottom middle top/ ];
+check_layers $seq, 'mods folding with layers 1',
+             <<'RES', [ qw/bottom middle top/ ];
 \begin{pgfonlayer}{bottom}
 \begin{scope} [color=red]
 \begin{pgfonlayer}{middle}
@@ -141,7 +136,8 @@ RES
 
 $baz->mod($top);
 
-check $seq, 'mods folding with layers 2', <<'RES', [ qw/bottom middle top/ ];
+check_layers $seq, 'mods folding with layers 2',
+             <<'RES', [ qw/bottom middle top/ ];
 \begin{pgfonlayer}{bottom}
 \begin{scope} [color=red]
 \begin{pgfonlayer}{middle}
@@ -160,7 +156,7 @@ RES
 my $seq2 = Tikz->seq($bar, $baz, $foo)
                ->mod($red);
 
-check $seq2, 'mods folding with layers 3', <<'RES', [ qw/middle top/ ];
+check_layers $seq2, 'mods folding with layers 3', <<'RES', [ qw/middle top/ ];
 \begin{scope} [color=red]
 \begin{pgfonlayer}{top}
 \begin{scope} [color=red]
@@ -178,7 +174,7 @@ my $qux = Tikz->raw('qux');
 $seq2 = Tikz->seq($qux, $foo)
             ->mod($red);
 
-check $seq2, 'mods folding with layers 4', <<'RES', [ 'middle' ];
+check_layers $seq2, 'mods folding with layers 4', <<'RES', [ 'middle' ];
 \begin{scope} [color=red]
 \draw qux ;
 \begin{pgfonlayer}{middle}
@@ -190,7 +186,7 @@ RES
 my $seq3 = Tikz->seq($seq2, $bar)
                ->mod($red);
 
-check $seq3, 'mods folding with layers 5', <<'RES', [ qw/middle top/ ];
+check_layers $seq3, 'mods folding with layers 5', <<'RES', [ qw/middle top/ ];
 \begin{scope} [color=red]
 \draw qux ;
 \begin{pgfonlayer}{middle}
@@ -205,7 +201,7 @@ RES
 $seq3 = Tikz->seq($bar, $seq2)
             ->mod($red);
 
-check $seq3, 'mods folding with layers 6', <<'RES', [ qw/middle top/ ];
+check_layers $seq3, 'mods folding with layers 6', <<'RES', [ qw/middle top/ ];
 \begin{scope} [color=red]
 \begin{pgfonlayer}{top}
 \draw [color=red] bar ;
@@ -220,7 +216,7 @@ RES
 my $blue = Tikz->color('blue');
 $qux->mod($blue);
 
-check $seq2, 'mods folding with layers 7', <<'RES', [ 'middle' ];
+check_layers $seq2, 'mods folding with layers 7', <<'RES', [ 'middle' ];
 \begin{scope} [color=red]
 \draw [color=blue] qux ;
 \begin{pgfonlayer}{middle}