]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - t/23-pattern.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/LaTeX-TikZ.git] / t / 23-pattern.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5 + 4 * 5;
7
8 use LaTeX::TikZ;
9
10 use lib 't/lib';
11 use LaTeX::TikZ::TestHelper;
12
13 using Tikz->formatter(
14  format => '%d',
15 );
16
17 sub check_patterns {
18  my ($set, $desc, $exp_decl, $exp) = @_;
19
20  local $Test::Builder::Level = $Test::Builder::Level + 1;
21
22  my ($head, $decl, $body) = check($set, $desc, $exp);
23
24  is $head->[-1], '\usetikzlibrary{patterns}', "$desc: header";
25
26  unless (ref $exp_decl eq 'ARRAY') {
27   $exp_decl = [ split /\n/, $exp_decl ];
28  }
29
30  is_deeply $decl, $exp_decl, "$desc: declarations";
31 }
32
33 my $lines = eval {
34  Tikz->raw("foo")
35      ->mod(Tikz->pattern(class => 'Lines'));
36 };
37 is $@, '', 'creating a line pattern doesn\'t croak';
38
39 check_patterns $lines, 'a line pattern', <<'DECL', <<'BODY';
40 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
41 \pgfsetlinewidth{0.2pt}
42 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.8pt}}
43 \pgfpathlineto{\pgfqpoint{1.8pt}{0.8pt}}
44 \pgfusepath{stroke}
45 }
46 DECL
47 \draw [fill,pattern=pata] foo ;
48 BODY
49
50 my $dots = eval {
51  Tikz->raw("foo")
52      ->mod(Tikz->pattern(class => 'Dots'));
53 };
54 is $@, '', 'creating a dot pattern doesn\'t croak';
55
56 check_patterns $dots, 'a dot pattern', <<'DECL', <<'BODY';
57 \pgfdeclarepatternformonly{patb}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
58 \pgfpathcircle{\pgfqpoint{0.8pt}{0.8pt}}{0.2pt}
59 \pgfusepath{fill}
60 }
61 DECL
62 \draw [fill,pattern=patb] foo ;
63 BODY
64
65 my ($lines_mod) = $lines->mods;
66 my ($dots_mod)  = $dots->mods;
67
68 my $seq = eval {
69  Tikz->seq(
70   Tikz->raw('foo')
71       ->mod($lines_mod)
72  )->mod($lines_mod);
73 };
74 is $@, '', 'creating a sequence with two identic patterns doesn\'t croak';
75
76 check_patterns $seq, 'a sequence with two identic patterns', <<'DECL', <<'BODY';
77 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
78 \pgfsetlinewidth{0.2pt}
79 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.8pt}}
80 \pgfpathlineto{\pgfqpoint{1.8pt}{0.8pt}}
81 \pgfusepath{stroke}
82 }
83 DECL
84 \draw [fill,pattern=pata] foo ;
85 BODY
86
87 $seq = eval {
88  Tikz->seq(
89   Tikz->raw('foo')
90       ->mod($lines_mod)
91  )->mod(Tikz->pattern(class => 'Lines', direction => 'vertical'));
92 };
93 is $@, '',
94          'creating a sequence with two orthogonal line patterns doesn\'t croak';
95
96 check_patterns $seq, 'a sequence with two orthogonal line patterns',
97                <<'DECL', <<'BODY';
98 \pgfdeclarepatternformonly{patc}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
99 \pgfsetlinewidth{0.2pt}
100 \pgfpathmoveto{\pgfqpoint{0.8pt}{-0.2pt}}
101 \pgfpathlineto{\pgfqpoint{0.8pt}{1.8pt}}
102 \pgfusepath{stroke}
103 }
104 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
105 \pgfsetlinewidth{0.2pt}
106 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.8pt}}
107 \pgfpathlineto{\pgfqpoint{1.8pt}{0.8pt}}
108 \pgfusepath{stroke}
109 }
110 DECL
111 \draw [fill,pattern=patc,pattern=pata] foo ;
112 BODY
113
114 $seq = eval {
115  Tikz->seq(
116   Tikz->raw('foo')
117       ->mod($lines_mod)
118  )->mod($dots_mod);
119 };
120 is $@, '', 'creating a sequence with two different patterns doesn\'t croak';
121
122 check_patterns $seq, 'a sequence with two different patterns',
123                <<'DECL', <<'BODY';
124 \pgfdeclarepatternformonly{patb}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
125 \pgfpathcircle{\pgfqpoint{0.8pt}{0.8pt}}{0.2pt}
126 \pgfusepath{fill}
127 }
128 \pgfdeclarepatternformonly{pata}{\pgfqpoint{-0.2pt}{-0.2pt}}{\pgfqpoint{1.8pt}{1.8pt}}{\pgfqpoint{1.6pt}{1.6pt}}{
129 \pgfsetlinewidth{0.2pt}
130 \pgfpathmoveto{\pgfqpoint{-0.2pt}{0.8pt}}
131 \pgfpathlineto{\pgfqpoint{1.8pt}{0.8pt}}
132 \pgfusepath{stroke}
133 }
134 DECL
135 \draw [fill,pattern=patb,pattern=pata] foo ;
136 BODY