6 use Test::More tests => 5 + 4 * 5;
10 my $tikz = Tikz->formatter(
15 my ($set, $desc, $exp_decl, $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 is $head->[-1], '\usetikzlibrary{patterns}', "$desc: header";
26 unless (ref $exp_decl eq 'ARRAY') {
27 $exp_decl = [ split /\n/, $exp_decl ];
30 unless (ref $exp eq 'ARRAY') {
31 $exp = [ split /\n/, $exp ];
33 unshift @$exp, '\begin{tikzpicture}';
34 push @$exp, '\end{tikzpicture}';
36 is_deeply $decl, $exp_decl, "$desc: declarations";
37 is_deeply $body, $exp, "$desc: body";
42 ->mod(Tikz->pattern(class => 'Lines'));
44 is $@, '', 'creating a line pattern doesn\'t croak';
46 check $lines, 'a line pattern', <<'DECL', <<'BODY';
47 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{0.3pt}{0.3pt}}{\pgfqpoint{0.2pt}{0.2pt}}{
48 \pgfsetlinewidth{0.2pt}
49 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.1pt}}
50 \pgfpathlineto{\pgfqpoint{0.3pt}{0.1pt}}
54 \draw [fill,pattern=pata] foo ;
59 ->mod(Tikz->pattern(class => 'Dots'));
61 is $@, '', 'creating a dot pattern doesn\'t croak';
63 check $dots, 'a dot pattern', <<'DECL', <<'BODY';
64 \pgfdeclarepatternformonly{patb}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{0.3pt}{0.3pt}}{\pgfqpoint{0.2pt}{0.2pt}}{
65 \pgfpathcircle{\pgfqpoint{0.1pt}{0.1pt}}{0.2pt}
69 \draw [fill,pattern=patb] foo ;
72 my ($lines_mod) = $lines->mods;
73 my ($dots_mod) = $dots->mods;
81 is $@, '', 'creating a sequence with two identic patterns doesn\'t croak';
83 check $seq, 'a sequence with two identic patterns', <<'DECL', <<'BODY';
84 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{0.3pt}{0.3pt}}{\pgfqpoint{0.2pt}{0.2pt}}{
85 \pgfsetlinewidth{0.2pt}
86 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.1pt}}
87 \pgfpathlineto{\pgfqpoint{0.3pt}{0.1pt}}
91 \draw [fill,pattern=pata] foo ;
98 )->mod(Tikz->pattern(class => 'Lines', direction => 'vertical'));
101 'creating a sequence with two orthogonal line patterns doesn\'t croak';
103 check $seq, 'a sequence with two orthogonal line patterns', <<'DECL', <<'BODY';
104 \pgfdeclarepatternformonly{patc}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{0.3pt}{0.3pt}}{\pgfqpoint{0.2pt}{0.2pt}}{
105 \pgfsetlinewidth{0.2pt}
106 \pgfpathmoveto{\pgfqpoint{0.1pt}{-0.2pt}}
107 \pgfpathlineto{\pgfqpoint{0.1pt}{0.3pt}}
110 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{0.3pt}{0.3pt}}{\pgfqpoint{0.2pt}{0.2pt}}{
111 \pgfsetlinewidth{0.2pt}
112 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.1pt}}
113 \pgfpathlineto{\pgfqpoint{0.3pt}{0.1pt}}
117 \draw [fill,pattern=patc,pattern=pata] foo ;
126 is $@, '', 'creating a sequence with two different patterns doesn\'t croak';
128 check $seq, 'a sequence with two different patterns', <<'DECL', <<'BODY';
129 \pgfdeclarepatternformonly{patb}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{0.3pt}{0.3pt}}{\pgfqpoint{0.2pt}{0.2pt}}{
130 \pgfpathcircle{\pgfqpoint{0.1pt}{0.1pt}}{0.2pt}
133 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{0.3pt}{0.3pt}}{\pgfqpoint{0.2pt}{0.2pt}}{
134 \pgfsetlinewidth{0.2pt}
135 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.1pt}}
136 \pgfpathlineto{\pgfqpoint{0.3pt}{0.1pt}}
140 \draw [fill,pattern=patb,pattern=pata] foo ;