]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - t/30-functor.t
Insert rules after all their subrules and before all their superrules
[perl/modules/LaTeX-TikZ.git] / t / 30-functor.t
index 30289c227be85a1a875ea24f0334bb3c54584fe3..bdade4b6c6257b1686636a263258de9d3e00582f 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 5 + 2 * 5;
+use Test::More tests => 10 + 2 * 7;
 
 use LaTeX::TikZ;
 
@@ -122,6 +122,42 @@ check $seq3, 'the stripped sequence', <<'RES';
 \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::Op'    => 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
+
 $tikz = eval {
  Tikz->formatter(
   origin => [ -1, 1 ],
@@ -141,4 +177,3 @@ check $seq, 'a sequence translated by an origin', <<'RES';
 \end{scope}
 \end{scope}
 RES
-