6 use Test::More tests => 12 + 2 * 7;
10 my $tikz = Tikz->formatter(
15 my ($set, $desc, $exp) = @_;
17 local $Test::Builder::Level = $Test::Builder::Level + 1;
19 my ($head, $decl, $body) = eval {
20 $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
22 is $@, '', "$desc: no error";
24 unless (ref $exp eq 'ARRAY') {
25 $exp = [ split /\n/, $exp ];
27 unshift @$exp, '\begin{tikzpicture}';
28 push @$exp, '\end{tikzpicture}';
30 is_deeply $body, $exp, $desc;
36 is $@, '', 'creating a raw set doesn\'t croak';
38 check $foo, 'one raw set', <<'RES';
43 Tikz->seq($foo, $foo);
45 is $@, '', 'creating a 2-sequence doesn\'t croak';
47 check $seq2, 'two identical raw sets', <<'RES';
55 is $@, '', 'creating another raw set doesn\'t croak';
58 Tikz->seq($foo, $bar);
60 is $@, '', 'creating another 2-sequence doesn\'t croak';
62 check $seq2, 'two different raw sets', <<'RES';
68 Tikz->seq($bar, $seq2, $foo);
70 is $@, '', 'creating a complex sequence doesn\'t croak';
72 check $seq3, 'two different raw sets and a sequence', <<'RES';
82 is $@, '', 'creating yet another raw set doesn\'t croak';
87 like $@, qr/Can't locate object method "add"/,
88 'adding something to a raw set croaks';
91 $seq2->add($baz, $baz);
93 is $@, '', 'adding something to a sequence set doesn\'t croak';
95 check $seq3, 'two different raw sets and an extended sequence', <<'RES';
106 qr/Validation failed for '\Q$tc\E'/;
109 my $err_path = qr/does not pass the type constraint because: Validation failed for 'Maybe\[ArrayRef\[LaTeX::TikZ::Set::Path::Elements\]\]/;
112 Tikz->path($foo, $seq2);
114 like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Path::Elements]]'),
115 'creating a path that contains a sequence croaks';
118 Tikz->path($foo, $bar, $baz);
120 is $@, '', 'creating a path set doesn\'t croak';
122 check $path, 'one path set', <<'RES';
129 is $@, '', 'adding something to a path set doesn\'t croak';
131 check Tikz->seq($path, $path), 'two identical path sets', <<'RES';
132 \draw foo bar baz foo ;
133 \draw foo bar baz foo ;
139 like $@, failed_valid('LaTeX::TikZ::Set::Path::Elements'),
140 'adding a sequence to a path croaks';