Debian Codegraph @

xt/large_data.t

raw symbols SCIP
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Test::TAPv13 ":all";
6 use Test::Deep;
7 use Test::More tests => 3;
8 use Data::DPath 'dpath';
9 use Data::Dumper;
10 use Clone 'clone';
11 use Benchmark ':all', ':hireswallclock';
12 use Devel::Size 'total_size';
13
14 # local $Data::DPath::DEBUG = 1;
15 local $Data::DPath::USE_SAFE = 0;
16
17 BEGIN {
18 use_ok( 'Data::DPath' );
19 }
20
21 my $base_data = {
22 'parse_errors' => [
23 'Bad plan. You planned 6 tests but ran 8.'
24 ],
25 'tests_run' => 8,
26 'version' => 13,
27 'exit' => 0,
28 'start_time' => '1236463400.25151',
29 'skip_all' => undef,
30 'lines' => [
31 {
32 'is_comment' => 0,
33 'has_skip' => 0,
34 'as_string' => 'TAP version 13',
35 'is_test' => 0,
36 'is_yaml' => 0,
37 'is_plan' => 0,
38 'is_actual_ok' => 0,
39 'is_unknown' => 0,
40 'has_todo' => 0,
41 'is_bailout' => 0,
42 'is_pragma' => 0,
43 'is_version' => 1,
44 'raw' => 'TAP version 13'
45 },
46 {
47 'is_comment' => 0,
48 'has_skip' => 0,
49 'as_string' => '1..6',
50 'is_test' => 0,
51 'is_yaml' => 0,
52 'is_plan' => 1,
53 'is_actual_ok' => 0,
54 'is_unknown' => 0,
55 'has_todo' => 0,
56 'is_bailout' => 0,
57 'is_pragma' => 0,
58 'is_version' => 0,
59 'raw' => '1..6'
60 },
61 {
62 'is_comment' => 0,
63 'is_yaml' => 0,
64 'is_plan' => 0,
65 'number' => '1',
66 'is_unknown' => 0,
67 'is_bailout' => 0,
68 'is_pragma' => 0,
69 'is_unplanned' => 0,
70 'as_string' => 'ok 1 - use Data::DPath;',
71 'has_skip' => 0,
72 'is_test' => 1,
73 '_children' => [
74 {
75 'is_comment' => 0,
76 'has_skip' => 0,
77 'as_string' => ' ---
78 - name: \'Hash one\'
79 value: 1
80 - name: \'Hash two\'
81 value: 2
82 ...',
83 'is_test' => 0,
84 'is_yaml' => 1,
85 'is_plan' => 0,
86 'data' => [
87 {
88 'value' => '1',
89 'name' => 'Hash one'
90 },
91 {
92 'value' => '2',
93 'name' => 'Hash two'
94 }
95 ],
96 'is_actual_ok' => 0,
97 'is_unknown' => 0,
98 'has_todo' => 0,
99 'is_bailout' => 0,
100 'is_pragma' => 0,
101 'is_version' => 0,
102 'raw' => ' ---
103 - name: \'Hash one\'
104 value: 1
105 - name: \'Hash two\'
106 value: 2
107 ...'
108 }
109 ],
110 'is_actual_ok' => 0,
111 'description' => '- use Data::DPath;',
112 'is_ok' => 1,
113 'has_todo' => 0,
114 'explanation' => '',
115 'directive' => '',
116 'type' => 'test',
117 'is_version' => 0,
118 'raw' => 'ok 1 - use Data::DPath;'
119 },
120 {
121 'is_comment' => 0,
122 'is_yaml' => 0,
123 'is_plan' => 0,
124 'number' => '2',
125 'is_unknown' => 0,
126 'is_bailout' => 0,
127 'is_pragma' => 0,
128 'is_unplanned' => 0,
129 'as_string' => 'ok 2 - KEYs + PARENT',
130 'has_skip' => 0,
131 'is_test' => 1,
132 'is_actual_ok' => 0,
133 'description' => '- KEYs + PARENT',
134 'is_ok' => 1,
135 'has_todo' => 0,
136 'explanation' => '',
137 'directive' => '',
138 'type' => 'test',
139 'is_version' => 0,
140 'raw' => 'ok 2 - KEYs + PARENT'
141 },
142 {
143 'is_comment' => 0,
144 'is_yaml' => 0,
145 'is_plan' => 0,
146 'number' => '3',
147 'is_unknown' => 0,
148 'is_bailout' => 0,
149 'is_pragma' => 0,
150 'is_unplanned' => 0,
151 'as_string' => 'ok 3 - quoted KEY containg slash',
152 'has_skip' => 0,
153 'is_test' => 1,
154 'is_actual_ok' => 0,
155 'description' => '- quoted KEY containg slash',
156 'is_ok' => 1,
157 'has_todo' => 0,
158 'explanation' => '',
159 'directive' => '',
160 'type' => 'test',
161 'is_version' => 0,
162 'raw' => 'ok 3 - quoted KEY containg slash'
163 },
164 {
165 'is_comment' => 0,
166 'has_skip' => 0,
167 'as_string' => 'pragma +strict',
168 'is_test' => 0,
169 'is_yaml' => 0,
170 'is_plan' => 0,
171 'is_actual_ok' => 0,
172 'is_unknown' => 0,
173 'has_todo' => 0,
174 'is_bailout' => 0,
175 'is_pragma' => 1,
176 'is_version' => 0,
177 'raw' => 'pragma +strict'
178 },
179 {
180 'is_comment' => 0,
181 'is_yaml' => 0,
182 'is_plan' => 0,
183 'number' => '4',
184 'is_unknown' => 0,
185 'is_bailout' => 0,
186 'is_pragma' => 0,
187 'is_unplanned' => 0,
188 'as_string' => 'not ok 4 # TODO spec only',
189 'has_skip' => 0,
190 'is_test' => 1,
191 '_children' => [
192 {
193 'is_comment' => 1,
194 'has_skip' => 0,
195 'as_string' => '# Failed (TODO) test at t/data_dpath.t line 144.',
196 'is_test' => 0,
197 'is_yaml' => 0,
198 'is_plan' => 0,
199 'is_actual_ok' => 0,
200 'is_unknown' => 0,
201 'has_todo' => 0,
202 'is_bailout' => 0,
203 'is_pragma' => 0,
204 'is_version' => 0,
205 'raw' => '# Failed (TODO) test at t/data_dpath.t line 144.'
206 },
207 {
208 'is_comment' => 1,
209 'has_skip' => 0,
210 'as_string' => '# Structures begin differing at:',
211 'is_test' => 0,
212 'is_yaml' => 0,
213 'is_plan' => 0,
214 'is_actual_ok' => 0,
215 'is_unknown' => 0,
216 'has_todo' => 0,
217 'is_bailout' => 0,
218 'is_pragma' => 0,
219 'is_version' => 0,
220 'raw' => '# Structures begin differing at:'
221 },
222 {
223 'is_comment' => 1,
224 'has_skip' => 0,
225 'as_string' => '# $got->[0] = Does not exist',
226 'is_test' => 0,
227 'is_yaml' => 0,
228 'is_plan' => 0,
229 'is_actual_ok' => 0,
230 'is_unknown' => 0,
231 'has_todo' => 0,
232 'is_bailout' => 0,
233 'is_pragma' => 0,
234 'is_version' => 0,
235 'raw' => '# $got->[0] = Does not exist'
236 },
237 {
238 'is_comment' => 1,
239 'has_skip' => 0,
240 'as_string' => '# $expected->[0] = ARRAY(0x8e4c238)',
241 'is_test' => 0,
242 'is_yaml' => 0,
243 'is_plan' => 0,
244 'is_actual_ok' => 0,
245 'is_unknown' => 0,
246 'has_todo' => 0,
247 'is_bailout' => 0,
248 'is_pragma' => 0,
249 'is_version' => 0,
250 'raw' => '# $expected->[0] = ARRAY(0x8e4c238)'
251 }
252 ],
253 'is_actual_ok' => 0,
254 'description' => '',
255 'is_ok' => 1,
256 'has_todo' => 1,
257 'explanation' => 'spec only',
258 'directive' => 'TODO',
259 'type' => 'test',
260 'is_version' => 0,
261 'raw' => 'not ok 4 # TODO spec only'
262 },
263 {
264 'is_comment' => 0,
265 'is_yaml' => 0,
266 'is_plan' => 0,
267 'number' => '5',
268 'is_unknown' => 0,
269 'is_bailout' => 0,
270 'is_pragma' => 0,
271 'is_unplanned' => 0,
272 'as_string' => 'ok 5 - ANYWHERE + KEY + FILTER int # TODO spec only',
273 'has_skip' => 0,
274 'is_test' => 1,
275 'is_actual_ok' => 1,
276 'description' => '- ANYWHERE + KEY + FILTER int',
277 'is_ok' => 1,
278 'has_todo' => 1,
279 'explanation' => 'spec only',
280 'directive' => 'TODO',
281 'type' => 'test',
282 'is_version' => 0,
283 'raw' => 'ok 5 - ANYWHERE + KEY + FILTER int # TODO spec only'
284 },
285 {
286 'is_comment' => 0,
287 'is_yaml' => 0,
288 'is_plan' => 0,
289 'number' => '6',
290 'is_unknown' => 0,
291 'is_bailout' => 0,
292 'is_pragma' => 0,
293 'is_unplanned' => 0,
294 'as_string' => 'ok 6 # SKIP rethink twice',
295 'has_skip' => 1,
296 'is_test' => 1,
297 'is_actual_ok' => 0,
298 'description' => '',
299 'is_ok' => 1,
300 'has_todo' => 0,
301 'explanation' => 'rethink twice',
302 'directive' => 'SKIP',
303 'type' => 'test',
304 'is_version' => 0,
305 'raw' => 'ok 6 # skip rethink twice'
306 },
307 {
308 'is_comment' => 0,
309 'is_yaml' => 0,
310 'is_plan' => 0,
311 'number' => '7',
312 'is_unknown' => 0,
313 'is_bailout' => 0,
314 'is_pragma' => 0,
315 'is_unplanned' => 1,
316 'as_string' => 'not ok 7 # TODO spec only',
317 'has_skip' => 0,
318 'is_test' => 1,
319 '_children' => [
320 {
321 'is_comment' => 1,
322 'has_skip' => 0,
323 'as_string' => '# Failed (TODO) test at t/data_dpath.t line 356.',
324 'is_test' => 0,
325 'is_yaml' => 0,
326 'is_plan' => 0,
327 'is_actual_ok' => 0,
328 'is_unknown' => 0,
329 'has_todo' => 0,
330 'is_bailout' => 0,
331 'is_pragma' => 0,
332 'is_version' => 0,
333 'raw' => '# Failed (TODO) test at t/data_dpath.t line 356.'
334 },
335 {
336 'is_comment' => 1,
337 'has_skip' => 0,
338 'as_string' => '# Structures begin differing at:',
339 'is_test' => 0,
340 'is_yaml' => 0,
341 'is_plan' => 0,
342 'is_actual_ok' => 0,
343 'is_unknown' => 0,
344 'has_todo' => 0,
345 'is_bailout' => 0,
346 'is_pragma' => 0,
347 'is_version' => 0,
348 'raw' => '# Structures begin differing at:'
349 },
350 {
351 'is_comment' => 1,
352 'has_skip' => 0,
353 'as_string' => '# $got->[0] = Does not exist',
354 'is_test' => 0,
355 'is_yaml' => 0,
356 'is_plan' => 0,
357 'is_actual_ok' => 0,
358 'is_unknown' => 0,
359 'has_todo' => 0,
360 'is_bailout' => 0,
361 'is_pragma' => 0,
362 'is_version' => 0,
363 'raw' => '# $got->[0] = Does not exist'
364 },
365 {
366 'is_comment' => 1,
367 'has_skip' => 0,
368 'as_string' => '# $expected->[0] = \'interesting value\'',
369 'is_test' => 0,
370 'is_yaml' => 0,
371 'is_plan' => 0,
372 'is_actual_ok' => 0,
373 'is_unknown' => 0,
374 'has_todo' => 0,
375 'is_bailout' => 0,
376 'is_pragma' => 0,
377 'is_version' => 0,
378 'raw' => '# $expected->[0] = \'interesting value\''
379 }
380 ],
381 'is_actual_ok' => 0,
382 'description' => '',
383 'is_ok' => 0,
384 'has_todo' => 1,
385 'explanation' => 'spec only',
386 'directive' => 'TODO',
387 'type' => 'test',
388 'is_version' => 0,
389 'raw' => 'not ok 7 # TODO spec only'
390 },
391 {
392 'is_comment' => 0,
393 'is_yaml' => 0,
394 'is_plan' => 0,
395 'number' => '8',
396 'is_unknown' => 0,
397 'is_bailout' => 0,
398 'is_pragma' => 0,
399 'is_unplanned' => 1,
400 'as_string' => 'ok 8 - FILTER eval regex # TODO too dirty, first cleanup _filter_eval',
401 'has_skip' => 0,
402 'is_test' => 1,
403 'is_actual_ok' => 1,
404 'description' => '- FILTER eval regex',
405 'is_ok' => 0,
406 'has_todo' => 1,
407 'explanation' => 'too dirty, first cleanup _filter_eval',
408 'directive' => 'TODO',
409 'type' => 'test',
410 'is_version' => 0,
411 'raw' => 'ok 8 - FILTER eval regex # TODO too dirty, first cleanup _filter_eval'
412 },
413 ],
414 'is_good_plan' => 0,
415 'has_problems' => 2,
416 'end_time' => '1236463400.25468',
417 'pragmas' => [
418 'strict'
419 ],
420 'plan' => '1..6',
421 'tests_planned' => 6
422 };
423
424 my $resultlist;
425
426 # ---------- prepare ----------
427
428 my $path = '//lines//description[ value =~ m(use Data::DPath) ]/../_children//data//name[ value eq "Hash two"]/../value';
429 my $expected = "2";
430
431 $resultlist = [ dpath($path)->match($base_data) ];
432 # diag Dumper($resultlist);
433 cmp_deeply $resultlist, [ $expected ], "base_data";
434
435 diag "Prepare big data...";
436 my $huge_data;
437 my $multi = 1000;
438 my @huge_expected = map { $expected } 1..$multi;
439 $huge_data->{$_} = clone ( $base_data ) foreach 1..$multi;
440 diag "Data size: ".total_size ($huge_data);
441
442 diag "Running benchmark. Can take some time ...";
443 my $count = 3;
444 my $t = timeit ($count, sub { $resultlist = [ dpath($path)->match($huge_data) ] });
445 my $n = $t->[5];
446 my $throughput = $n / $t->[0];
447 #diag Dumper($huge_data);
448 # diag Dumper(\@huge_expected);
449 # diag Dumper($resultlist);
450 diag Dumper($t);
451 cmp_deeply $resultlist, [ @huge_expected ], "huge_data";
452 tap13_yaml({ benchmark => {
453 timestr => timestr($t),
454 wallclock => $t->[0],
455 usr => $t->[1],
456 sys => $t->[2],
457 throughput => $throughput,
458 },
459 });