6 use Test::More tests => 11 + 2 * 8;
11 use LaTeX::TikZ::TestHelper;
13 using Tikz->formatter(
17 my $translate = eval {
19 'LaTeX::TikZ::Set::Point' => sub {
20 my ($functor, $set, $v) = @_;
33 is $@, '', 'creating a translator doesn\'t croak';
40 ->clip(Tikz->circle(1, 1)),
42 Tikz->chain(4 => '--' => [ -3, 2 ]),
43 Tikz->join('-|' => [ -1, 0 ], [ 0, 1 ]),
46 ->clip(Tikz->rectangle([0, -1] => [2, 3]));
49 $seq->$translate(Tikz->point(-1, 1));
51 is $@, '', 'translating a sequence doesn\'t croak';
53 check $seq, 'the original sequence', <<'RES';
55 \clip (0cm,-1cm) rectangle (2cm,3cm) ;
60 \clip (1cm,0cm) circle (1cm) ;
61 \draw (-1cm,0cm) -- (3cm,0cm) ;
63 \draw (4cm,0cm) -- (-3cm,2cm) (-1cm,0cm) -| (0cm,1cm) ;
67 check $seq2, 'the translated sequence', <<'RES';
69 \clip (-1cm,0cm) rectangle (1cm,4cm) ;
74 \clip (0cm,1cm) circle (1cm) ;
75 \draw (-2cm,1cm) -- (2cm,1cm) ;
77 \draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ;
81 my $poly = Tikz->closed_polyline(
82 [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ]
86 $poly->$translate(Tikz->point(-1, 1));
88 is $@, '', 'translating a polyline doesn\'t croak';
90 check $poly2, 'the translated polyline', <<'RES';
91 \draw (-1cm,1cm) -- (0cm,1cm) -- (0cm,2cm) -- (-1cm,2cm) -- cycle ;
96 '+LaTeX::TikZ::Mod' => sub { return },
99 is $@, '', 'creating a stripper doesn\'t croak';
101 $_->mod(Tikz->color('red')) for $seq2->kids;
106 is $@, '', 'stripping a sequence doesn\'t croak';
108 check $seq2, 'the original sequence', <<'RES';
109 \begin{scope} [color=red]
110 \clip (-1cm,0cm) rectangle (1cm,4cm) ;
115 \clip (0cm,1cm) circle (1cm) ;
116 \draw (-2cm,1cm) -- (2cm,1cm) ;
118 \draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ;
122 check $seq3, 'the stripped sequence', <<'RES';
126 \draw (-2cm,1cm) -- (2cm,1cm) ;
127 \draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ;
132 '+LaTeX::TikZ::Mod' => sub { die "mod\n" },
133 '+LaTeX::TikZ::Set' => sub { die "set\n" },
136 is $@, '', 'creating a special functor with + rules doesn\'t croak';
138 eval { $seq->$special };
139 is $@, "set\n", 'special functor with + rules eats everything properly';
143 '+LaTeX::TikZ::Mod' => sub { die "mod\n" },
144 '+LaTeX::TikZ::Set' => sub { die "set\n" },
145 'LaTeX::TikZ::Set::Point' => sub { Tikz->point(7) },
146 'LaTeX::TikZ::Set::Path' => sub { Tikz->raw('moo') },
149 is $@, '', 'creating a special functor with + and normal rules doesn\'t croak';
151 my $res = eval { Tikz->point(3, 4)->$special };
152 is $@, '', 'special functor with + and normal rules orders its rules properly';
154 check $res, 'the result of the special functor', <<'RES';
158 $res = eval { Tikz->raw('hlagh')->$special };
160 'special functor with + and normal rules orders its rules properly again';
162 check $res, 'the result of the special functor', <<'RES';
171 is $@, '', 'creating a formatter object with an origin doesn\'t croak';
173 check $seq, 'a sequence translated by an origin', <<'RES';
175 \clip (-1cm,0cm) rectangle (1cm,4cm) ;
180 \clip (0cm,1cm) circle (1cm) ;
181 \draw (-2cm,1cm) -- (2cm,1cm) ;
183 \draw (3cm,1cm) -- (-4cm,3cm) (-2cm,1cm) -| (-1cm,2cm) ;