Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Rewrote ABC.pm to solve the 'choose' problem #158

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 0 additions & 48 deletions lib/DDG/Goodie/ABC.pm

This file was deleted.

28 changes: 28 additions & 0 deletions lib/DDG/Goodie/AorB.pm
@@ -0,0 +1,28 @@
package DDG::Goodie::AorB;

use DDG::Goodie;

triggers any => "pick", "choose", "or";

zci answer_type => "rand";

handle query_lc => sub {
return unless /^(?:pick|choose)?\s*((?:[^\s]+)(?:\s+[^\s]+)*(?:\s+or\s+(?:[^\s]+))+)$/;
my @query = split(' ', $1);
my @del = grep{ $query[$_] eq 'or' } 0..$#query;
my $pick;
my $a = 0;
for (@del) {
splice(@query, $_-$a, 1);
$a++;
}
if (my @duck = grep { / \A (?: duck (?: duckgo )? | ddg ) \z /ix } @query) {
return $duck[0]." (not random)", answer_type => 'egg';
}

$pick = $query[int rand @query];
return $pick." (random)";

};

1;
22 changes: 0 additions & 22 deletions t/ABC.t

This file was deleted.

25 changes: 25 additions & 0 deletions t/AorB.t
@@ -0,0 +1,25 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;

zci answer_type => 'rand';
zci is_cached => 0;

ddg_goodie_test(
[qw(
DDG::Goodie::AorB
)],
'a or b' => test_zci(qr/(a|b) \(random\)/),
'a b or c' => test_zci(qr/(a|b|c) \(random\)/),
'choose a or b' => test_zci(qr/(a|b) \(random\)/),
'choose a b or c' => test_zci(qr/(a|b|c) \(random\)/),
'pick a or b' => test_zci(qr/(a|b) \(random\)/),
'pick a b or c' => test_zci(qr/(a|b|c) \(random\)/),
'@#$ or 1i4' => test_zci(qr/(\@\#\$|1i4) \(random\)/),
'duckduckgo or google' => test_zci("duckduckgo (not random)", answer_type => 'egg'),
);

done_testing;