mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 16:55:42 -04:00
Add a test for the oeis plugin.
In the process I extracted a function.
This commit is contained in:
parent
3a36f3965b
commit
a1f08b1315
2 changed files with 30 additions and 11 deletions
|
@ -6,15 +6,13 @@ use CGI;
|
||||||
use LWP::Simple;
|
use LWP::Simple;
|
||||||
use WWW::Shorten 'TinyURL';
|
use WWW::Shorten 'TinyURL';
|
||||||
|
|
||||||
sub {
|
sub query_oeis {
|
||||||
my($said) = @_;
|
my ($q)=@_;
|
||||||
my $q = $said->{"body"};
|
|
||||||
|
|
||||||
warn 1;
|
warn 1;
|
||||||
if( $q =~ /^\s*(?:(?:help|wtf|\?|\:)\s*)?$/i )
|
if( $q =~ /^\s*(?:(?:help|wtf|\?|\:)\s*)?$/i )
|
||||||
{
|
{
|
||||||
print "see http://oeis.org/";
|
return([], ["see http://oeis.org/"]);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
warn 2;
|
warn 2;
|
||||||
my $uri = "http://oeis.org/search?q=" . CGI::escape($q)."&fmt=text";
|
my $uri = "http://oeis.org/search?q=" . CGI::escape($q)."&fmt=text";
|
||||||
|
@ -24,8 +22,7 @@ sub {
|
||||||
my $nrfound = $1;
|
my $nrfound = $1;
|
||||||
unless( /^%N (\S+) (.*)/m )
|
unless( /^%N (\S+) (.*)/m )
|
||||||
{
|
{
|
||||||
print "Reply from OEIS in unknown format 2";
|
return([ "Reply from OEIS in unknown format 2"],[]);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
warn 3;
|
warn 3;
|
||||||
my($anum, $title) = ($1, $2);
|
my($anum, $title) = ($1, $2);
|
||||||
|
@ -35,21 +32,28 @@ sub {
|
||||||
warn 3.5;
|
warn 3.5;
|
||||||
if (1 == $nrfound) {
|
if (1 == $nrfound) {
|
||||||
my $outuri = sprintf "http://oeis.org/%s", $anum;
|
my $outuri = sprintf "http://oeis.org/%s", $anum;
|
||||||
print sprintf "%s %.256s: %.512s", $outuri, $title, $elts;
|
return ([],[sprintf( "%s %.256s: %.512s", $outuri, $title, $elts)]);
|
||||||
} else {
|
} else {
|
||||||
my $outuri1 = "http://oeis.org/searchs?q=" . CGI::escape($q);
|
my $outuri1 = "http://oeis.org/searchs?q=" . CGI::escape($q);
|
||||||
warn 3.6;
|
warn 3.6;
|
||||||
# my $outuri = makeashorterlink($outuri1) || $outuri1;
|
# my $outuri = makeashorterlink($outuri1) || $outuri1;
|
||||||
print sprintf "%s %.10s(1/%d) %.256s: %.512s", $outuri1, $anum, $nrfound, $title, $elts;
|
return([], [sprintf( "%s %.10s(1/%d) %.256s: %.512s", $outuri1, $anum, $nrfound, $title, $elts)]);
|
||||||
}
|
}
|
||||||
} elsif (/^no matches/mi) {
|
} elsif (/^no matches/mi) {
|
||||||
print "No matches found";
|
return([], ["No matches found"]);
|
||||||
warn 4
|
warn 4
|
||||||
} else {
|
} else {
|
||||||
warn 5;
|
warn 5;
|
||||||
print "Reply from OEIS in unknown format: $_";
|
return([ "Reply from OEIS in unknown format: $_"], []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub {
|
||||||
|
my($said) = @_;
|
||||||
|
my $q = $said->{"body"};
|
||||||
|
my ($err, $out) = query_oeis($q);
|
||||||
|
print "Error: @$err\n" if @$err;
|
||||||
|
print "@$out\n";
|
||||||
|
}
|
||||||
__DATA__
|
__DATA__
|
||||||
Search for a sequence in the On-Line Encyclopedia of Integer Sequences (http://tinyurl.com/2blo2w) Syntax, oeis 1,1,2,3,5
|
Search for a sequence in the On-Line Encyclopedia of Integer Sequences (http://tinyurl.com/2blo2w) Syntax, oeis 1,1,2,3,5
|
||||||
|
|
15
t/oeis-plugin.t
Normal file
15
t/oeis-plugin.t
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use utf8;
|
||||||
|
use Test::More tests => 1;
|
||||||
|
use lib '.';
|
||||||
|
use plugins::oeis;
|
||||||
|
|
||||||
|
# TEST
|
||||||
|
like(
|
||||||
|
(query_oeis("1,2,6,24"))[1][0],
|
||||||
|
qr#https?://oeis\.org/.*?Factorial numbers: n!#ms,
|
||||||
|
"factorials",
|
||||||
|
);
|
Loading…
Add table
Reference in a new issue