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}