X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=blobdiff_plain;f=t%2F10-set.t;h=1476558a54e56789ab3bd960cddcce7ed641376b;hp=9d20422f25d0da150350051c5b6cd0ab7e9787ce;hb=95aada0ec5b3c5a0d78ed0ad53436b0e70860bc7;hpb=1c53f7e28198adfb2905667acd5741f163832d7b diff --git a/t/10-set.t b/t/10-set.t index 9d20422..1476558 100644 --- a/t/10-set.t +++ b/t/10-set.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 19 + 2 * 14; +use Test::More tests => 28 + 2 * 21; use LaTeX::TikZ; @@ -162,27 +162,102 @@ eval { like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Path]]'), 'creating an union that contains a sequence croaks'; -my $path = eval { +my $union = eval { Tikz->union($foo, $bar, $baz); }; is $@, '', 'creating an union set doesn\'t croak'; -check $path, 'one path set', <<'RES'; +check $union, 'one union set', <<'RES'; \draw foo bar baz ; RES eval { - $path->add($foo); + $union->add($foo); }; -is $@, '', 'adding something to a path set doesn\'t croak'; +is $@, '', 'adding something to a union set doesn\'t croak'; -check Tikz->seq($path, $path), 'two identical path sets', <<'RES'; +check Tikz->seq($union, $union), 'two identical union sets', <<'RES'; \draw foo bar baz foo ; \draw foo bar baz foo ; RES eval { - $path->add($seq2); + $union->add($seq2); }; like $@, failed_valid('LaTeX::TikZ::Set::Path'), - 'adding a sequence to a path croaks'; + 'adding a sequence to a union croaks'; + +my $join = eval { + Tikz->join('--' => $foo, $bar, $baz); +}; +is $@, '', 'creating an chain set joined with a string doesn\'t croak'; + +check $join, 'one chain set joined with a string', <<'RES'; +\draw foo -- bar -- baz ; +RES + +eval { + $join->add($foo); +}; +is $@, '', 'adding a set to a chain set joined with a string doesn\'t croak'; + +check $join, 'one appended chain set joined with a string', <<'RES'; +\draw foo -- bar -- baz -- foo ; +RES + +$join = eval { + Tikz->join(sub { ' ' } => $foo, $bar, $baz); +}; +is $@, '', 'creating an chain set joined with a coderef doesn\'t croak'; + +check $join, 'one chain set joined with a string', <<'RES'; +\draw foo bar baz ; +RES + +eval { + $join->add($foo); +}; +is $@, '', 'adding a set to a chain set joined with a coderef doesn\'t croak'; + +check $join, 'one appended chain set joined with a coderef', <<'RES'; +\draw foo bar baz foo ; +RES + +$join = eval { + Tikz->join([ '', '..', '--' ] => $foo, $bar, $baz); +}; +is $@, '', 'creating an chain set joined with an arrayref doesn\'t croak'; + +check $join, 'one chain set joined with a string', <<'RES'; +\draw foo bar .. baz ; +RES + +eval { + $join->add($foo); +}; +is $@, '', 'adding a set to a chain set joined with an arrayref doesn\'t croak'; + +check $join, 'one appended chain set joined with an arrayref', <<'RES'; +\draw foo bar .. baz -- foo ; +RES + +eval { + $join->add($bar); +}; +like $@, qr/^Invalid connector/, + 'adding too many sets to a chain set joined with an arrayref croaks'; + +my $chain = eval { + Tikz->chain($foo => '--' => $bar => '->' => $baz); +}; +is $@, '', 'creating an chain set with chain doesn\'t croak'; + +check $chain, 'one chain set from chain', <<'RES'; +\draw foo -- bar -> baz ; +RES + +eval { + Tikz->chain($foo, '--', $bar, '--'); +}; +like $@, qr/^The 'chain' command expects an odd number of arguments/, + 'creating an union that contains a sequence croaks';