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 = '1017'; |
5
|
3
|
|
|
15
|
|
17680
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
74
|
|
6
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
57
|
|
7
|
3
|
|
|
3
|
|
12
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
127
|
|
8
|
3
|
|
|
3
|
|
14
|
use Test::More; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
15
|
|
9
|
3
|
|
|
3
|
|
1243
|
use DDG::Test::Block; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
13
|
|
10
|
3
|
|
|
3
|
|
1013
|
use DDG::ZeroClickInfo::Spice; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
83
|
|
11
|
3
|
|
|
3
|
|
1100
|
use DDG::Meta::ZeroClickInfoSpice; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
114
|
|
12
|
3
|
|
|
3
|
|
27
|
use Package::Stash; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
70
|
|
13
|
3
|
|
|
3
|
|
15
|
use Class::Load 'load_class'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1284
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
17
|
3
|
|
|
3
|
|
37
|
my ( $class, %params ) = @_; |
18
|
3
|
|
|
|
|
9
|
my $target = caller; |
19
|
3
|
|
|
|
|
42
|
my $stash = Package::Stash->new($target); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
9
|
my %spice_params = ( |
23
|
|
|
|
|
|
|
call_type => 'include', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$stash->add_symbol('&test_spice', sub { |
27
|
11
|
|
|
11
|
|
480
|
my $call = shift; |
28
|
|
|
|
|
|
|
ref $_[0] eq 'HASH' |
29
|
11
|
50
|
|
|
|
195
|
? DDG::ZeroClickInfo::Spice->new(%spice_params, %{$_[0]}, call => $call ) |
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
: DDG::ZeroClickInfo::Spice->new(%spice_params, @_, call => $call ) |
31
|
3
|
|
|
|
|
52
|
}); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$stash->add_symbol('&spice', sub { |
35
|
0
|
0
|
|
0
|
|
0
|
if (ref $_[0] eq 'HASH') { |
|
|
|
|
0
|
|
|
|
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
|
|
|
|
|
22
|
}); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$stash->add_symbol('&ddg_spice_test', sub { block_test(sub { |
50
|
11
|
|
|
11
|
|
20
|
my $query = shift; |
51
|
11
|
|
|
|
|
16
|
my $answer = shift; |
52
|
11
|
|
|
|
|
15
|
my $spice = shift; |
53
|
11
|
50
|
|
|
|
23
|
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
|
|
19
|
},@_)}); |
|
1
|
|
|
|
|
18
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$stash->add_symbol('&alt_to_test', sub { |
62
|
1
|
|
|
1
|
|
1031
|
my ($spice, $alt_tos) = @_; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
7
|
load_class($spice); |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
101
|
my $rewrites = $spice->alt_rewrites; |
67
|
1
|
|
|
|
|
7
|
ok($rewrites, "$spice has rewrites"); |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
415
|
ok($spice =~ /^(DDG.+::)/, "Extract base from $spice"); |
70
|
1
|
|
|
|
|
415
|
my $base = $1; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
4
|
for my $alt (@$alt_tos){ |
73
|
2
|
|
|
|
|
460
|
my ($cb, $path) = @{DDG::Meta::ZeroClickInfoSpice::params_from_target("$base$alt")}; |
|
2
|
|
|
|
|
10
|
|
74
|
2
|
|
|
|
|
6
|
my $rw = $rewrites->{$alt}; |
75
|
2
|
|
|
|
|
9
|
ok($rw, "$alt exists"); |
76
|
2
|
|
|
|
|
793
|
ok($rw->callback eq $cb, "$alt callback"); |
77
|
2
|
|
|
|
|
811
|
ok($rw->path eq $path, "$alt path"); |
78
|
|
|
|
|
|
|
} |
79
|
3
|
|
|
|
|
85
|
}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |