| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DDG::Test::Spice; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:DDG'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Adds keywords to easily test Spice plugins. |
|
4
|
|
|
|
|
|
|
$DDG::Test::Spice::VERSION = '1018'; |
|
5
|
3
|
|
|
14
|
|
74005
|
use strict; |
|
|
3
|
|
|
|
|
21
|
|
|
|
3
|
|
|
|
|
109
|
|
|
6
|
3
|
|
|
3
|
|
22
|
use warnings; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
117
|
|
|
7
|
3
|
|
|
3
|
|
21
|
use Carp; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
237
|
|
|
8
|
3
|
|
|
3
|
|
23
|
use Test::More; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
29
|
|
|
9
|
3
|
|
|
3
|
|
1931
|
use DDG::Test::Block; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
12
|
|
|
10
|
3
|
|
|
3
|
|
910
|
use DDG::ZeroClickInfo::Spice; |
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
109
|
|
|
11
|
3
|
|
|
3
|
|
1238
|
use DDG::Meta::ZeroClickInfoSpice; |
|
|
3
|
|
|
|
|
16
|
|
|
|
3
|
|
|
|
|
169
|
|
|
12
|
3
|
|
|
3
|
|
40
|
use Package::Stash; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
82
|
|
|
13
|
3
|
|
|
3
|
|
19
|
use Class::Load 'load_class'; |
|
|
3
|
|
|
|
|
10
|
|
|
|
3
|
|
|
|
|
1760
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
|
17
|
3
|
|
|
3
|
|
41
|
my ( $class, %params ) = @_; |
|
18
|
3
|
|
|
|
|
11
|
my $target = caller; |
|
19
|
3
|
|
|
|
|
60
|
my $stash = Package::Stash->new($target); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
12
|
my %spice_params = ( |
|
23
|
|
|
|
|
|
|
call_type => 'include', |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$stash->add_symbol('&test_spice', sub { |
|
27
|
11
|
|
|
11
|
|
254
|
my $call = shift; |
|
28
|
|
|
|
|
|
|
ref $_[0] eq 'HASH' |
|
29
|
11
|
50
|
|
|
|
184
|
? DDG::ZeroClickInfo::Spice->new(%spice_params, %{$_[0]}, call => $call ) |
|
|
0
|
|
|
|
|
0
|
|
|
30
|
|
|
|
|
|
|
: DDG::ZeroClickInfo::Spice->new(%spice_params, @_, call => $call ) |
|
31
|
3
|
|
|
|
|
63
|
}); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$stash->add_symbol('&spice', sub { |
|
35
|
0
|
0
|
|
0
|
|
0
|
if (ref $_[0] eq 'HASH') { |
|
36
|
0
|
|
|
|
|
0
|
for (keys %{$_[0]}) { |
|
|
0
|
|
|
|
|
0
|
|
|
37
|
0
|
|
|
|
|
0
|
$spice_params{$_} = $_[0]->{$_}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} else { |
|
40
|
0
|
|
|
|
|
0
|
while (@_) { |
|
41
|
0
|
|
|
|
|
0
|
my $key = shift; |
|
42
|
0
|
|
|
|
|
0
|
my $value = shift; |
|
43
|
0
|
|
|
|
|
0
|
$spice_params{$key} = $value; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
3
|
|
|
|
|
29
|
}); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$stash->add_symbol('&ddg_spice_test', sub { block_test(sub { |
|
50
|
11
|
|
|
11
|
|
19
|
my $query = shift; |
|
51
|
11
|
|
|
|
|
17
|
my $answer = shift; |
|
52
|
11
|
|
|
|
|
15
|
my $spice = shift; |
|
53
|
11
|
50
|
|
|
|
22
|
if ($answer) { |
|
54
|
11
|
|
|
|
|
46
|
is_deeply($answer,$spice,'Testing query '.$query); |
|
55
|
|
|
|
|
|
|
} else { |
|
56
|
0
|
|
|
|
|
0
|
fail('Expected result but dont get one on '.$query); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
3
|
|
|
1
|
|
23
|
},@_)}); |
|
|
1
|
|
|
|
|
11
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$stash->add_symbol('&alt_to_test', sub { |
|
62
|
1
|
|
|
1
|
|
751
|
my ($spice, $alt_tos) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
5
|
load_class($spice); |
|
65
|
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
92
|
my $rewrites = $spice->alt_rewrites; |
|
67
|
1
|
|
|
|
|
7
|
ok($rewrites, "$spice has rewrites"); |
|
68
|
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
247
|
ok($spice =~ /^(DDG.+::)/, "Extract base from $spice"); |
|
70
|
1
|
|
|
|
|
214
|
my $base = $1; |
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
2
|
for my $alt (@$alt_tos){ |
|
73
|
2
|
|
|
|
|
307
|
my ($cb, $path) = @{DDG::Meta::ZeroClickInfoSpice::params_from_target("$base$alt")}; |
|
|
2
|
|
|
|
|
8
|
|
|
74
|
2
|
|
|
|
|
6
|
my $rw = $rewrites->{$alt}; |
|
75
|
2
|
|
|
|
|
7
|
ok($rw, "$alt exists"); |
|
76
|
2
|
|
|
|
|
428
|
ok($rw->callback eq $cb, "$alt callback"); |
|
77
|
2
|
|
|
|
|
412
|
ok($rw->path eq $path, "$alt path"); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
3
|
|
|
|
|
108
|
}); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |