6 use Test::More tests => 10 + 2 * 7;
10 my $tikz = Tikz->formatter(
15 my ($set, $desc, $exp) = @_;
17 local $Test::Builder::Level = $Test::Builder::Level + 1;
19 my ($head, $decl, $body) = eval {
20 $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
22 is $@, '', "$desc: no error";
24 unless (ref $exp eq 'ARRAY') {
25 $exp = [ split /\n/, $exp ];
27 unshift @$exp, '\begin{tikzpicture}';
28 push @$exp, '\end{tikzpicture}';
30 is_deeply $body, $exp, $desc;
33 my $translate = eval {
35 'LaTeX::TikZ::Set::Point' => sub {
36 my ($functor, $set, $v) = @_;
49 is $@, '', 'creating a translator doesn\'t croak';
56 ->clip(Tikz->circle(1, 1))
58 ->clip(Tikz->rectangle([0, -1] => [2, 3]));
61 $seq->$translate(Tikz->point(-1, 1));
63 is $@, '', 'translating a sequence doesn\'t croak';
65 check $seq, 'the original sequence', <<'RES';
67 \clip (0cm,-1cm) rectangle (2cm,3cm) ;
72 \clip (1cm,0cm) circle (1cm) ;
73 \draw (-1cm,0cm) -- (3cm,0cm) ;
78 check $seq2, 'the translated sequence', <<'RES';
80 \clip (-1cm,0cm) rectangle (1cm,4cm) ;
85 \clip (0cm,1cm) circle (1cm) ;
86 \draw (-2cm,1cm) -- (2cm,1cm) ;
93 '+LaTeX::TikZ::Mod' => sub { return },
96 is $@, '', 'creating a stripper doesn\'t croak';
98 $_->mod(Tikz->color('red')) for $seq2->kids;
103 is $@, '', 'stripping a sequence doesn\'t croak';
105 check $seq2, 'the original sequence', <<'RES';
106 \begin{scope} [color=red]
107 \clip (-1cm,0cm) rectangle (1cm,4cm) ;
112 \clip (0cm,1cm) circle (1cm) ;
113 \draw (-2cm,1cm) -- (2cm,1cm) ;
118 check $seq3, 'the stripped sequence', <<'RES';
122 \draw (-2cm,1cm) -- (2cm,1cm) ;
127 '+LaTeX::TikZ::Mod' => sub { die "mod\n" },
128 '+LaTeX::TikZ::Set' => sub { die "set\n" },
131 is $@, '', 'creating a special functor with + rules doesn\'t croak';
133 eval { $seq->$special };
134 is $@, "set\n", 'special functor with + rules eats everything properly';
138 '+LaTeX::TikZ::Mod' => sub { die "mod\n" },
139 '+LaTeX::TikZ::Set' => sub { die "set\n" },
140 'LaTeX::TikZ::Set::Point' => sub { Tikz->point(7) },
141 'LaTeX::TikZ::Set::Op' => sub { Tikz->raw('moo') },
144 is $@, '', 'creating a special functor with + and normal rules doesn\'t croak';
146 my $res = eval { Tikz->point(3, 4)->$special };
147 is $@, '', 'special functor with + and normal rules orders its rules properly';
149 check $res, 'the result of the special functor', <<'RES';
153 $res = eval { Tikz->raw('hlagh')->$special };
155 'special functor with + and normal rules orders its rules properly again';
157 check $res, 'the result of the special functor', <<'RES';
166 is $@, '', 'creating a formatter object with an origin doesn\'t croak';
168 check $seq, 'a sequence translated by an origin', <<'RES';
170 \clip (-1cm,0cm) rectangle (1cm,4cm) ;
175 \clip (0cm,1cm) circle (1cm) ;
176 \draw (-2cm,1cm) -- (2cm,1cm) ;