From: Vincent Pit <vince@profvince.com>
Date: Sun, 18 Jul 2010 08:47:09 +0000 (+0200)
Subject: Fix Set::Path->add
X-Git-Tag: v0.01~57
X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=6ad93fc8c0660b952c41f0d435683ecb5fe9102a;p=perl%2Fmodules%2FLaTeX-TikZ.git

Fix Set::Path->add
---

diff --git a/lib/LaTeX/TikZ/Set/Path.pm b/lib/LaTeX/TikZ/Set/Path.pm
index b8d9768..0b695c6 100644
--- a/lib/LaTeX/TikZ/Set/Path.pm
+++ b/lib/LaTeX/TikZ/Set/Path.pm
@@ -42,9 +42,9 @@ my $ltspe_tc = find_type_constraint('LaTeX::TikZ::Set::Path::Elements');
 sub add {
  my $set = shift;
 
- $ltspe_tc->check($_) for @_;
+ $ltspe_tc->assert_valid($_) for @_;
 
- push @{$_[0]->_ops}, @_;
+ push @{$set->_ops}, @_;
 
  $set;
 }
diff --git a/t/10-set.t b/t/10-set.t
index 029fccd..69008ae 100644
--- a/t/10-set.t
+++ b/t/10-set.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9 + 2 * 6;
+use Test::More tests => 12 + 2 * 7;
 
 use LaTeX::TikZ;
 use LaTeX::TikZ::Formatter;
@@ -100,12 +100,40 @@ check $seq3, 'two different raw sets and an extended sequence', <<'RES';
 \draw foo ;
 RES
 
+sub failed_valid {
+ my ($tc) = @_;
+ qr/Validation failed for '\Q$tc\E'/;
+}
+
+my $err_path = qr/does not pass the type constraint because: Validation failed for 'Maybe\[ArrayRef\[LaTeX::TikZ::Set::Path::Elements\]\]/;
+
+eval {
+ Tikz->path($foo, $seq2);
+};
+like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Path::Elements]]'),
+         'creating a path that contains a sequence croaks';
+
 my $path = eval {
  Tikz->path($foo, $bar, $baz);
 };
 is $@, '', 'creating a path set doesn\'t croak';
 
-check [ $path, $path ], 'two identical path sets', <<'RES';
-\draw foo bar baz ;
+check $path, 'one path set', <<'RES';
 \draw foo bar baz ;
 RES
+
+eval {
+ $path->add($foo);
+};
+is $@, '', 'adding something to a path set doesn\'t croak';
+
+check [ $path, $path ], 'two identical path sets', <<'RES';
+\draw foo bar baz foo ;
+\draw foo bar baz foo ;
+RES
+
+eval {
+ $path->add($seq2);
+};
+like $@, failed_valid('LaTeX::TikZ::Set::Path::Elements'),
+         'adding a sequence to a path croaks';