]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - t/30-functor.t
Make LT::Set::Path the base role, remove ::Op, and rename the old ::Path to ::Union
[perl/modules/LaTeX-TikZ.git] / t / 30-functor.t
index 347b5399295680fd848a86b08c46e82f572ade4f..a5952efe26f1f09053a3e17d00aa50586a68ab59 100644 (file)
@@ -1,35 +1,19 @@
-#!perl
+#!perl -T
 
 use strict;
 use warnings;
 
-use Test::More tests => 4 + 2 * 4;
+use Test::More tests => 10 + 2 * 7;
 
 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 {
@@ -40,6 +24,8 @@ my $translate = eval {
      $set->x + $v->x,
      $set->y + $v->y,
     ],
+    label => $set->label,
+    pos   => $set->pos,
    );
   },
  );
@@ -88,7 +74,7 @@ RES
 
 my $strip = eval {
  Tikz->functor(
-  'LaTeX::TikZ::Mod' => sub { return },
+  '+LaTeX::TikZ::Mod' => sub { return },
  );
 };
 is $@, '', 'creating a stripper doesn\'t croak';
@@ -119,3 +105,59 @@ check $seq3, 'the stripped sequence', <<'RES';
 \draw (1cm,1cm) ;
 \draw (-2cm,1cm) -- (2cm,1cm) ;
 RES
+
+my $special = eval {
+ Tikz->functor(
+  '+LaTeX::TikZ::Mod' => sub { die "mod\n" },
+  '+LaTeX::TikZ::Set' => sub { die "set\n" },
+ );
+};
+is $@, '', 'creating a special functor with + rules doesn\'t croak';
+
+eval { $seq->$special };
+is $@, "set\n", 'special functor with + rules eats everything properly';
+
+$special = eval {
+ Tikz->functor(
+  '+LaTeX::TikZ::Mod'       => sub { die "mod\n" },
+  '+LaTeX::TikZ::Set'       => sub { die "set\n" },
+  'LaTeX::TikZ::Set::Point' => sub { Tikz->point(7) },
+  'LaTeX::TikZ::Set::Path'  => sub { Tikz->raw('moo') },
+ );
+};
+is $@, '', 'creating a special functor with + and normal rules doesn\'t croak';
+
+my $res = eval { Tikz->point(3, 4)->$special };
+is $@, '', 'special functor with + and normal rules orders its rules properly';
+
+check $res, 'the result of the special functor', <<'RES';
+\draw (7cm,0cm) ;
+RES
+
+$res = eval { Tikz->raw('hlagh')->$special };
+is $@, '',
+      'special functor with + and normal rules orders its rules properly again';
+
+check $res, 'the result of the special functor', <<'RES';
+\draw moo ;
+RES
+
+using eval {
+ Tikz->formatter(
+  origin => [ -1, 1 ],
+ );
+};
+is $@, '', 'creating a formatter object with an origin doesn\'t croak';
+
+check $seq, 'a sequence translated by an origin', <<'RES';
+\begin{scope}
+\clip (-1cm,0cm) rectangle (1cm,4cm) ;
+\draw (-1cm,1cm) ;
+\draw foo ;
+\draw (1cm,1cm) ;
+\begin{scope}
+\clip (0cm,1cm) circle (1cm) ;
+\draw (-2cm,1cm) -- (2cm,1cm) ;
+\end{scope}
+\end{scope}
+RES