use strict;
use warnings;
-use Test::More tests => (14 + 2 * 5) + 2 * (11 + 2 * 3);
+use Test::More tests => (16 + 2 * 5) + 2 * (13 + 2 * 3);
use Math::Complex;
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'/;
\draw (-1cm,2cm) -- (3cm,-4cm) ;
RES
+# Arrow
+
+my $ar = eval {
+ Tikz->arrow($o, 1);
+};
+is $@, '', 'creating an arrow from two points doesn\'t croak';
+
+check $ar, 'an arrow from two points', <<'RES';
+\draw [->] (0cm,0cm) -- (1cm,0cm) ;
+RES
+
+$ar = eval {
+ Tikz->arrow(2, dir => -i());
+};
+is $@, '', 'creating an arrow from a point and a direction doesn\'t croak';
+
+check $ar, 'an arrow from a point and a direction', <<'RES';
+\draw [->] (2cm,0cm) -- (2cm,-1cm) ;
+RES
+
# Polyline
my $w = Tikz->point(3, -4);
like $@, qr/at least two LaTeX::TikZ::Set::Point objects are needed in order to build a polyline/, "creating a $desc from only one Tikz point croaks";
$pl = eval {
- Tikz->$polyline(qw/foo bar/);
+ Tikz->$polyline(qw<foo bar>);
};
like $@, failed_valid('LaTeX::TikZ::Point::Autocoerce'), "creating a $desc from two string croaks";
}
eval {
Tikz->circle($o => -1);
};
-like $@, qr/isn't a non-negative real number/,
+like $@, failed_valid('__ANON__'),
'creating a circle with a negative radius croaks';
# Arc
-$tikz = Tikz->formatter(
+using Tikz->formatter(
format => "%.03f"
);