PageRenderTime 72ms CodeModel.GetById 40ms app.highlight 18ms RepoModel.GetById 12ms app.codeStats 0ms

/t/Teto-Track.t

http://github.com/motemen/Teto
Unknown | 95 lines | 81 code | 14 blank | 0 comment | 0 complexity | b9e93d4bc933e2e7e313052c2c70afd2 MD5 | raw file
 1use strict;
 2use lib 'lib';
 3use Test::More tests => 11;
 4use Test::Deep;
 5
 6use_ok 'Teto::Track';
 7
 8my $track = new_ok 'Teto::Track', [ url => '' ];
 9
10cmp_set [ Teto::Track->subclasses ], [
11    qw(Teto::Track::NicoVideo::sm Teto::Track::NicoVideo::nm Teto::Track::YouTube Teto::Track::SoundCloud Teto::Track::System)
12], 'subclasses';
13
14subtest nicovideo_sm => sub {
15    my $track = Teto::Track->from_url('http://www.nicovideo.jp/watch/sm11809611');
16    isa_ok $track, 'Teto::Track::NicoVideo::sm';
17};
18
19subtest nicovideo_nm => sub {
20    my $track = Teto::Track->from_url('http://www.nicovideo.jp/watch/nm3254039');
21    isa_ok $track, 'Teto::Track::NicoVideo::nm';
22};
23
24subtest soundcloud => sub {
25    my $track = Teto::Track->from_url('http://soundcloud.com/takuma-hosokawa/darksidenadeko-electro-mix');
26    isa_ok $track, 'Teto::Track::SoundCloud';
27};
28
29subtest 'none handles' => sub {
30    my $track = Teto::Track->from_url('http://www.example.com/');
31    ok not $track;
32};
33
34subtest play => sub {
35    my $track = new_ok 't::Track', [ url => '' ];
36    $track->play;
37    $track->play;
38    is $track->{play_count}, 1;
39};
40
41subtest track_id => sub {
42    my $track = new_ok 't::Track', [ url => '' ];
43    ok $track->track_id;
44    is $track, Teto::Track->of_track_id($track->track_id);
45};
46
47subtest buffer_gc => sub {
48    local $Teto::Track::BufferCache = Cache::LRU::Peekable->new(size => 2);
49    my @tracks;
50    for (0 .. 9) {
51        my $track = Teto::Track->new(url => '');
52        $track->append_buffer("track $_");
53        is $track->buffer, "track $_";
54        push @tracks, $track;
55    }
56    foreach (0 .. 7) {
57        ok !$tracks[$_]->has_buffer;
58        # is $tracks[$_]->buffer, '' # XXX calling $track->buffer confuses underlying LRU cache
59    }
60    foreach (8 .. 9) {
61        ok $tracks[$_]->has_buffer;
62        # is $tracks[$_]->buffer, "track $_";
63    }
64};
65
66subtest buffer_gc_peek => sub {
67    local $Teto::Track::BufferCache = Cache::LRU::Peekable->new(size => 2);
68    my @tracks;
69    for (0 .. 9) {
70        my $track = Teto::Track->new(url => '');
71        $track->append_buffer("track $_");
72        is $track->buffer, "track $_";
73        push @tracks, $track;
74    }
75    foreach (0 .. 7) {
76        ok !$tracks[$_]->has_buffer;
77        $tracks[$_]->peek_buffer_length;
78    }
79    foreach (8 .. 9) {
80        ok $tracks[$_]->has_buffer;
81        # is $tracks[$_]->buffer, "track $_";
82    }
83};
84
85BEGIN {
86    package t::Track;
87    use Mouse;
88
89    extends 'Teto::Track';
90
91    override _play => sub {
92        my $self = shift;
93        $self->{play_count}++;
94    };
95}