summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/pgfplots/test/pgfkeysaddition/pgfkeysadditiontest.tex
blob: 0670f283cca95e73ba0ec7049d56d35a1f406907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
\documentclass[a4paper]{article}

\usepackage[intlimits]{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{ifpdf}

\ifpdf
\else
\def\pgfsysdriver{pgfsys-dvipdfm.def}
\fi
\usepackage{tikz}
\usepackage{pgfplots}

\parindent=0pt

\def\testsection#1{\message{---------- STARTING TEST SECTION '#1'}\section{#1}}
\def\testsubsection#1{\message{-------STARTING TEST SUBSECTION '#1'}\subsection{#1}}
\def\testsubsubsection#1{\message{------STARTING TEST SUBSUBSECTION '#1'}\subsubsection{#1}}

\author{Christian Feuers\"anger}
\title{Test cases for pgfkeysaddition.sty}

\begin{document}
\maketitle

\pgfkeys{/my group/option1/.code={\message{/my group/option1 set to '#1'!}}}
\pgfkeys{/my group/option2/.code={\message{/my group/option2 set to '#1'!}}}
\pgfkeys{/my other group/O1/.code={\message{/my other group/O1 set to '#1'!}}}
\pgfkeys{/my other group/O2/.code={\message{/my other group/O2 set to '#1'!}}}

\pgfkeys{/pgf/key filter handlers/log/.install key filter handler}%

\testsection{Testing the `is descendant of -- predicate'}
\pgfkeys{/pgf/key filters/is descendant of/.install key filter={/my group}}%
\tracingmacros=2\tracingcommands=2
\pgfkeysfiltered%
	{/my group/.cd,option1=value for option1,/my other group/O1=value for O1}%
\tracingmacros=0\tracingcommands=0

\testsubsection{Testing it for a tikz style}
\tikzstyle{mein style}=[/my group/option1=option1 value in a style!,/tikz/line width=1pt]
\pgfkeys{/pgf/key filters/is descendant of/.install key filter={/my group}}%
\pgfkeysfiltered%
	{/my group/.cd,option1=value for option1,/my other group/O1=value for O1,/tikz/mein style}%


\testsection{Testing filtering for errors}
\testsubsection{unknown handler in /my group/}
{
\pgfkeys{/my group/.unknown/.code=\message{'#1' is unknown and the handler /my group/.unknown has been invoked!}}%
\pgfkeys{/pgf/key filters/is descendant of/.install key filter={/my group}}%
\pgfkeysfiltered%
	{/my group/.cd,option1=value for option1,option42=42}%
}

\testsubsection{unknown handler in /handlers/}
{
\pgfkeys{/handlers/.unknown/.code=\message{'#1' is unknown and the handler /handlers/.unknown has been invoked!}}%
\pgfkeys{/pgf/key filters/is descendant of/.install key filter={/my group}}%
\pgfkeysfiltered%
	{/my group/.cd,option1=value for option1,option42=42}%
}


\testsubsection{Check whether error messages come through}
{
\pgfkeys{/errors/mein fehler/.code=\message{My error message came through. That's good!}}%
\pgfkeys{/handlers/.unknown/.code=\pgfkeysalso{/errors/mein fehler=foo}}%
\pgfkeys{/pgf/key filters/is descendant of/.install key filter={/my group}}%
\pgfkeysfiltered%
	{/my group/.cd,option1=value for option1,option42=42}%
}

\testsection{Checking single key selection}
{
\pgfkeys{/test/a/.code=\message{'/test/a' is currently running; that's correct.}}%
\pgfkeys{/test/b/.code=\errmessage{'/test/b' shouldn't run! test failed!}}%
\pgfkeyssetvalue{/test/c}{Value of 'c'}%
\pgfkeys{/test/d/.style={/test/a=bar}}%

\testsubsection{command keys: select only /test/a}
\pgfkeys{/pgf/key filters/equals/.install key filter={/test/a}}
\pgfkeysfiltered%
	{/test/a=4,/test/b=5}

\testsubsection{value keys: select only /test/c}
\pgfkeys{/pgf/key filters/equals/.install key filter={/test/c}}
\pgfkeysfiltered%
	{/test/a=4,/test/b=5,/test/c=7}

\testsubsection{handler keys: select only /test/d}
\pgfkeys{/pgf/key filters/equals/.install key filter={/test/d}}
\pgfkeysfiltered%
	{/test/a=4,/test/b=5,/test/d}
}


\testsection{Checking logical combinations}
{
\pgfkeys{/test/a/.code=\message{'/test/a' is currently running; that's correct.}}%
\pgfkeys{/test/b/.code=\errmessage{'/test/b' shouldn't run! test failed!}}%
\pgfkeys{/test/c/.code=\message{'/test/c' is currently running; that's correct.}}%
\pgfkeys{/my group/A/.code=\message{'/my group/A' is currently running, that's correct.}}

\testsubsection{NOT = /test/b}
\pgfkeys{/pgf/key filters/not/.install key filter={/pgf/key filters/equals=/test/b}}
\pgfkeysfiltered%
	{/test/a=4,/test/b=5,/test/c}

\testsubsection{AND}
\pgfkeys{/pgf/key filters/and/.install key filter={{/pgf/key filters/equals={/test/a}}{/pgf/key filters/is descendant of=/test}}}
\pgfkeysfiltered%
	{/test/a=4,/test/b=5,/test/c}

\testsubsection{OR}
\pgfkeys{/pgf/key filters/or/.install key filter={{/pgf/key filters/equals={/test/a}}{/pgf/key filters/is descendant of=/my group}}}
\pgfkeysfiltered%
	{/test/a=4,/test/b=5,/my group/A=value 1}
}

\testsection{Testing filtered key collection}
{
\testsubsection{full keys}
\tracingmacros=2\tracingcommands=2
\pgfkeys{/pgf/key filters/is descendant of/.install key filter=/my group}
\def\filtered{}%
\pgfkeys{/pgf/key filter handlers/append filtered to/.install key filter handler=\filtered}%
\pgfkeysfiltered%
	{/my group/.cd,option1=value for option1,/my other group/O1=value for O1,/my other group/O2=value for O2}%
\message{filtered = '\filtered'}
\filtered

\testsubsection{partial keys}
\def\filtered{}%
\pgfkeys{/pgf/key filters/or/.install key filter={{/pgf/key filters/is descendant of=/my group}{/pgf/key filters/equals=/my other group/.cd}}}
\pgfkeysfiltered%
	{/my group/.cd,option1=value for option1,/my other group/.cd,O1=value for O1,O2= value for O2}%
\tracingmacros=2\tracingcommands=2
\message{filtered = '\filtered'}
\tracingmacros=0\tracingcommands=0
\filtered

\testsubsubsection{setting remaining keys}
\pgfkeys{/my other group/.cd,/utils/exec=\pgfkeysalsofrom\filtered}
}%


\testsection{Testing search paths}
{
\pgfkeys{/my search path/.unknown/.code={%
		\let\searchname=\pgfkeyscurrentname%
		\pgfkeysalso{%
			/my group/\searchname/.try=#1,
			/my other group/\searchname/.lastretry=#1
		}%
	}%
}
\pgfkeys{/my other group/.unknown/.code=\message{/my other/group/.unknown: called with unknown option '#1'.}}%

\testsubsection{First: no filtering}
\pgfkeys{/my search path/.cd,option1=value for option1,O1=value for O1,an unknown option=foo}

%--------------------------------------------------
% \testsubsection{Second: with filtering}
% \pgfkeysfiltered%
% 	{\pgfkeysisdescendantoftwo{/my group}{/my search path}}%
% 	{\pgfkeyslogfiltered}%
% 	{/my search path/.cd,option1=value for option1,O1=value for O1,an unknown option=foo}
% }
% 
%-------------------------------------------------- 

\testsection{Testing pgfkeysalsofiltered}
{
\def\filtered{}%
\pgfkeys{/pgf/key filter handlers/append filtered to/.install key filter handler=\filtered}%

\pgfkeys{/pgf/key filters/is descendant of/.install key filter=/my group}
\pgfkeys{/my group/.cd,/utils/exec=\pgfkeysalsofiltered
		{option1= value for option1,/my other group/O1=value for O1}}
}

\testsection{Testing family handling}
{
\testsubsection{testing .is family init:}
\pgfkeys{/my group/.is family}
\pgfkeysisfamilyactive{/my group}
\ifpgfkeysfiltercontinue
	\errmessage{TEST FAILED: /my group active: TRUE (EXPECTED FALSE)}%
\else
	\message{/my group active: FALSE (correct)}%
\fi

\testsubsection{testing .activate family:}
\pgfkeys{/my group/.activate family}
\pgfkeysisfamilyactive{/my group}
\ifpgfkeysfiltercontinue
	\message{/my group active: TRUE (correct)}%
\else
	\errmessage{TEST FAILED: /my group active: FALSE (EXPECTED: TRUE)}%
\fi

\testsubsection{testing .deactivate family:}
\pgfkeys{/my group/.deactivate family}
\pgfkeysisfamilyactive{/my group}
\ifpgfkeysfiltercontinue
	\errmessage{TEST FAILED: /my group active: TRUE (EXPECTED FALSE)}%
\else
	\message{/my group active: FALSE (correct)}%
\fi

\testsubsection{Testing filtering by active family}
{
\pgfkeys{/family1/.is family}
\pgfkeys{/family2/.is family}
\pgfkeys{/test/a/.code=\message{'/test/a' is currently running; that's correct.}}%
\pgfkeys{/test/a/.belongs to family=/family1}

\pgfkeys{/test/b/.code=\errmessage{'/test/b' shouldn't run! test failed!}}%
\pgfkeys{/test/b/.belongs to family=/family2}%

\pgfkeys{/test/c/.code=\errmessage{'/test/c' shouldn't run! test failed! }}%
\pgfkeys{/test/d/.code=\message{'/test/d' currently running. Ok.}}
\pgfkeys{/test/d/.belongs to family=/family2}

\testsubsubsection{first: only /test/a should run}%
\pgfkeys{/family1/.activate family}
\pgfkeys{
	/pgf/key filters/active families/.install key filter,
	/pgf/key filter handlers/log/.install key filter handler}

\pgfkeysfiltered
	{/test/a=value for a,/test/b=value for b,/test/c=value for c}

\testsubsubsection{second: no option should run}%
\pgfkeys{/family1/.deactivate family}

\pgfkeysfiltered
	{/test/a=value for a,/test/b=value for b,/test/c=value for c}


\testsubsubsection{once more again with dynamic family list detection pgfqkeysactivatefamiliesandfilteroptions}
\tracingmacros=2\tracingcommands=2
\pgfqkeysactivatefamiliesandfilteroptions{/family1,/family2}{/test}
	{a=value for a,c=value for c,d=value for d}
\tracingmacros=0\tracingcommands=0
}}


\end{document}