6 use Test::More tests => 12 + 2 * 7;
9 use LaTeX::TikZ::Formatter;
11 my $tikz = LaTeX::TikZ::Formatter->new(
16 my ($set, $desc, $exp) = @_;
18 local $Test::Builder::Level = $Test::Builder::Level + 1;
20 my ($head, $decl, $body) = eval {
21 $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
23 is $@, '', "$desc: no error";
25 unless (ref $exp eq 'ARRAY') {
26 $exp = [ split /\n/, $exp ];
28 unshift @$exp, '\begin{tikzpicture}';
29 push @$exp, '\end{tikzpicture}';
31 is_deeply $body, $exp, $desc;
37 is $@, '', 'creating a raw set doesn\'t croak';
39 check $foo, 'one raw set', <<'RES';
44 Tikz->seq($foo, $foo);
46 is $@, '', 'creating a 2-sequence doesn\'t croak';
48 check $seq2, 'two identical raw sets', <<'RES';
56 is $@, '', 'creating another raw set doesn\'t croak';
59 Tikz->seq($foo, $bar);
61 is $@, '', 'creating another 2-sequence doesn\'t croak';
63 check $seq2, 'two different raw sets', <<'RES';
69 Tikz->seq($bar, $seq2, $foo);
71 is $@, '', 'creating a complex sequence doesn\'t croak';
73 check $seq3, 'two different raw sets and a sequence', <<'RES';
83 is $@, '', 'creating yet another raw set doesn\'t croak';
88 like $@, qr/Can't locate object method "add"/,
89 'adding something to a raw set croaks';
92 $seq2->add($baz, $baz);
94 is $@, '', 'adding something to a sequence set doesn\'t croak';
96 check $seq3, 'two different raw sets and an extended sequence', <<'RES';
107 qr/Validation failed for '\Q$tc\E'/;
110 my $err_path = qr/does not pass the type constraint because: Validation failed for 'Maybe\[ArrayRef\[LaTeX::TikZ::Set::Path::Elements\]\]/;
113 Tikz->path($foo, $seq2);
115 like $@, failed_valid('Maybe[ArrayRef[LaTeX::TikZ::Set::Path::Elements]]'),
116 'creating a path that contains a sequence croaks';
119 Tikz->path($foo, $bar, $baz);
121 is $@, '', 'creating a path set doesn\'t croak';
123 check $path, 'one path set', <<'RES';
130 is $@, '', 'adding something to a path set doesn\'t croak';
132 check [ $path, $path ], 'two identical path sets', <<'RES';
133 \draw foo bar baz foo ;
134 \draw foo bar baz foo ;
140 like $@, failed_valid('LaTeX::TikZ::Set::Path::Elements'),
141 'adding a sequence to a path croaks';