t/92-pod-coverage.t
t/95-portability-files.t
t/99-kwalitee.t
+t/lib/LaTeX/TikZ/TestHelper.pm
t/lib/LaTeX/TikZ/TestX/FromTestY.pm
use LaTeX::TikZ;
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
format => '%d',
);
-sub check {
- my ($set, $desc, $exp) = @_;
-
- 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}';
-
- is_deeply $body, $exp, $desc;
-}
-
my $foo = eval {
Tikz->raw('foo');
};
use LaTeX::TikZ;
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
format => '%d',
);
-sub check {
- my ($set, $desc, $exp) = @_;
-
- 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}';
-
- is_deeply $body, $exp, $desc;
-}
-
my $z = Math::Complex->make(1, 2);
my $p = eval {
use LaTeX::TikZ;
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
format => '%d',
);
-sub check {
- my ($set, $desc, $exp) = @_;
-
- 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}';
-
- is_deeply $body, $exp, $desc;
-}
-
sub failed_valid {
my ($tc) = @_;
qr/Validation failed for '\Q$tc\E'/;
# Arc
-$tikz = Tikz->formatter(
+using Tikz->formatter(
format => "%.03f"
);
use LaTeX::TikZ;
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
format => '%d',
);
-sub check {
- my ($set, $desc, $exp) = @_;
-
- 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}';
-
- is_deeply $body, $exp, $desc;
-}
-
my $red = eval {
Tikz->color('red');
};
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),
];
is_deeply $decl, $exp_decl, "$desc: declarations";
- is_deeply $body, $exp, "$desc: body";
}
my $middle = 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}
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}
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 ;
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}
$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}
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]
$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}
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}
$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 ;
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}
use LaTeX::TikZ;
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
format => '%d',
);
-sub check {
- my ($set, $desc, $exp) = @_;
-
- 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}';
-
- is_deeply $body, $exp, $desc;
-}
-
my $clip1 = Tikz->raw('clip1');
my $clip2 = Tikz->raw('clip2');
use LaTeX::TikZ;
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
format => '%d',
);
-sub check {
+sub check_patterns {
my ($set, $desc, $exp_decl, $exp) = @_;
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";
+ my ($head, $decl, $body) = check($set, $desc, $exp);
is $head->[-1], '\usetikzlibrary{patterns}', "$desc: header";
$exp_decl = [ split /\n/, $exp_decl ];
}
- unless (ref $exp eq 'ARRAY') {
- $exp = [ split /\n/, $exp ];
- }
- unshift @$exp, '\begin{tikzpicture}';
- push @$exp, '\end{tikzpicture}';
-
is_deeply $decl, $exp_decl, "$desc: declarations";
- is_deeply $body, $exp, "$desc: body";
}
my $lines = eval {
};
is $@, '', 'creating a line pattern doesn\'t croak';
-check $lines, 'a line pattern', <<'DECL', <<'BODY';
+check_patterns $lines, 'a line pattern', <<'DECL', <<'BODY';
\pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
\pgfsetlinewidth{0.2pt}
\pgfpathmoveto{\pgfqpoint{-0.2pt}{0.8pt}}
};
is $@, '', 'creating a dot pattern doesn\'t croak';
-check $dots, 'a dot pattern', <<'DECL', <<'BODY';
+check_patterns $dots, 'a dot pattern', <<'DECL', <<'BODY';
\pgfdeclarepatternformonly{patb}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
\pgfpathcircle{\pgfqpoint{0.8pt}{0.8pt}}{0.2pt}
\pgfusepath{fill}
};
is $@, '', 'creating a sequence with two identic patterns doesn\'t croak';
-check $seq, 'a sequence with two identic patterns', <<'DECL', <<'BODY';
+check_patterns $seq, 'a sequence with two identic patterns', <<'DECL', <<'BODY';
\pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
\pgfsetlinewidth{0.2pt}
\pgfpathmoveto{\pgfqpoint{-0.2pt}{0.8pt}}
is $@, '',
'creating a sequence with two orthogonal line patterns doesn\'t croak';
-check $seq, 'a sequence with two orthogonal line patterns', <<'DECL', <<'BODY';
+check_patterns $seq, 'a sequence with two orthogonal line patterns',
+ <<'DECL', <<'BODY';
\pgfdeclarepatternformonly{patc}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
\pgfsetlinewidth{0.2pt}
\pgfpathmoveto{\pgfqpoint{0.8pt}{-0.2pt}}
};
is $@, '', 'creating a sequence with two different patterns doesn\'t croak';
-check $seq, 'a sequence with two different patterns', <<'DECL', <<'BODY';
+check_patterns $seq, 'a sequence with two different patterns',
+ <<'DECL', <<'BODY';
\pgfdeclarepatternformonly{patb}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
\pgfpathcircle{\pgfqpoint{0.8pt}{0.8pt}}{0.2pt}
\pgfusepath{fill}
use LaTeX::TikZ;
-my $tikz = Tikz->formatter(
+use lib 't/lib';
+use LaTeX::TikZ::TestHelper;
+
+using Tikz->formatter(
format => '%d',
);
-sub check {
- my ($set, $desc, $exp) = @_;
-
- 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}';
-
- is_deeply $body, $exp, $desc;
-}
-
my $translate = eval {
Tikz->functor(
'LaTeX::TikZ::Set::Point' => sub {
\draw moo ;
RES
-$tikz = eval {
+using eval {
Tikz->formatter(
origin => [ -1, 1 ],
);
--- /dev/null
+package LaTeX::TikZ::TestHelper;
+
+use strict;
+use warnings;
+
+use Test::More ();
+
+use Any::Moose 'Exporter';
+
+any_moose('Exporter')->setup_import_methods(
+ as_is => [ qw<using check> ],
+);
+
+my $tikz;
+
+sub using {
+ $tikz = $_[0] if defined $_[0];
+
+ return $tikz;
+}
+
+sub check {
+ my ($set, $desc, $exp) = @_;
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ my ($head, $decl, $body) = eval {
+ $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
+ };
+ Test::More::is($@, '', "$desc: no error");
+
+ unless (ref $exp eq 'ARRAY') {
+ $exp = [ split /\n/, $exp ];
+ }
+ unshift @$exp, '\begin{tikzpicture}';
+ push @$exp, '\end{tikzpicture}';
+
+ Test::More::is_deeply($body, $exp, "$desc: body");
+
+ return $head, $decl, $body;
+}
+
+1;