File: lookup_users.t

package info (click to toggle)
libnet-twitter-perl 3.13008-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 656 kB
  • ctags: 235
  • sloc: perl: 5,408; makefile: 4
file content (69 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!perl
use warnings;
use strict;
use Test::More;
use Net::Twitter;

eval "use LWP::UserAgent 5.819";
plan skip_all => 'LWP::UserAgent >= 5.819 required' if $@;

eval "use Test::Deep";
plan skip_all => 'Test::Deep required' if $@;

my @tests = (
    {
        args   => [ { user_id => '1234,6543,3333' } ],
        expect => { user_id => [ 1234, 6543, 3333 ] },
        name   => 'hash: comma delimited',
    },
    {
        args   => [ user_id => '1234,6543,3333' ],
        expect => { user_id => [ 1234, 6543, 3333 ] },
        name   => 'list: comma delimited',
    },
    {
        args   => [ { user_id => [ 1234, 6543, 3333 ] } ],
        expect => { user_id => [ 1234, 6543, 3333 ] },
        name   => 'hash: arrayref',
    },
    {
        args   => [ { screen_name => 'fred,barney,wilma' } ],
        expect => { screen_name => [qw/fred barney wilma/] },
        name   => 'hash: comma delimited',
    },
    {
        args   => [ screen_name => ['fred', 'barney', 'wilma'] ],
        expect => { screen_name => [qw/fred barney wilma/] },
        name   => 'list: arrayref',
    },
    {
        args   => [ screen_name => ['fred', 'barney' ], user_id => '4321,6789' ],
        expect => { screen_name => [qw/fred barney/], user_id => [ 4321, 6789 ] },
        name   => 'list: arrayref screen_name and comma delimited user_id',
    },
);

my $test_count = 0;
$test_count += keys %$_ for map { $_->{expect} } @tests;

plan tests => $test_count;

my $nt = Net::Twitter->new(legacy => 0);

my $req;
$nt->ua->add_handler(request_send => sub {
    $req = shift;
    my $res = HTTP::Response->new(200);
    $res->content('{"test":"ok"}');
    return $res;
});

for my $test ( @tests ) {
    my $r = $nt->lookup_users(@{ $test->{args} });

    my %query = $req->uri->query_form;
    for my $arg ( keys %{ $test->{expect} } ) {
        cmp_bag([ split /,/, $query{$arg} ], $test->{expect}{$arg}, "$test->{name} [$arg]");
    }
}