App-DrivePlayer
view release on metacpan or search on metacpan
t/unit/Test/DrivePlayer/Scanner.pm view on Meta::CPAN
package Test::DrivePlayer::Scanner;
use strict;
use warnings;
use utf8;
use Module::Load qw( load );
use Test::Most;
use Test::DrivePlayer::TestBase;
use Test::DrivePlayer::Utils qw( :all );
use parent 'Test::DrivePlayer::TestBase';
sub setup : Tests(setup) {
my ($self) = @_;
$self->SUPER::setup();
Module::Load::load('App::DrivePlayer::Scanner');
$self->{db} = fake_db($self->_temp_db_path);
return;
}
sub db { $_[0]->{db} }
# ---- _parse_filename (internal function, tested directly) ----
sub parse_filename_artist_title : Tests(4) {
my ($self) = @_;
my ($title, $artist) = App::DrivePlayer::Scanner::_parse_filename('Queen - Bohemian Rhapsody.mp3');
is $title, 'Bohemian Rhapsody', 'artist-title: title correct';
is $artist, 'Queen', 'artist-title: artist correct';
my ($title2, $artist2) = App::DrivePlayer::Scanner::_parse_filename('Led Zeppelin â Kashmir.flac');
is $title2, 'Kashmir', 'em-dash separator works: title';
is $artist2, 'Led Zeppelin', 'em-dash separator works: artist';
}
sub parse_filename_track_artist_title : Tests(4) {
my ($self) = @_;
my ($title, $artist, undef, $track_num) =
App::DrivePlayer::Scanner::_parse_filename('01 - Queen - Bohemian Rhapsody.mp3');
is $title, 'Bohemian Rhapsody', 'track-artist-title: title correct';
is $artist, 'Queen', 'track-artist-title: artist correct';
is $track_num, 1, 'track-artist-title: track_number correct';
(undef, undef, undef, my $tn2) =
App::DrivePlayer::Scanner::_parse_filename('11. Artist - Title.mp3');
is $tn2, 11, 'dot separator for track number';
}
sub parse_filename_track_title : Tests(3) {
my ($self) = @_;
my ($title, $artist, undef, $track_num) =
App::DrivePlayer::Scanner::_parse_filename('03 - Stairway to Heaven.flac');
is $title, 'Stairway to Heaven', 'track-title: title correct';
is $artist, undef, 'track-title: artist is undef';
is $track_num, 3, 'track-title: track_number correct';
}
sub parse_filename_title_only : Tests(3) {
my ($self) = @_;
my ($title, $artist, undef, $track_num) =
App::DrivePlayer::Scanner::_parse_filename('Untitled Track.ogg');
is $title, 'Untitled Track', 'title-only: title correct';
is $artist, undef, 'title-only: artist is undef';
is $track_num, undef, 'title-only: track_number is undef';
}
sub parse_filename_year_extraction : Tests(2) {
my ($self) = @_;
my ($title, undef, undef, undef, $year) =
App::DrivePlayer::Scanner::_parse_filename('Bohemian Rhapsody (1975).mp3');
( run in 0.448 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )