Browse Source

* t/utils-timing.t : refactoring

master
Alex 'AdUser' Z 6 years ago
parent
commit
e445187fd5
  1. 54
      t/utils-timing.t

54
t/utils-timing.t

@ -5,40 +5,20 @@ use Test::More tests => 11;
use Subtitle::Utils qw(:timing); use Subtitle::Utils qw(:timing);
my ($timing, $time); ## parse_timing()
# valid timecodes
$timing = "123:11:15.459"; is(parse_timing('123:11:15.459'), (123 * 3600 + 11 * 60 + 15 + 0.459));
$time = parse_timing($timing); is(parse_timing('123:11:15.45'), (123 * 3600 + 11 * 60 + 15 + 0.450));
is($time, (123 * 3600 + 11 * 60 + 15 + 0.459)); is(parse_timing('123:11:15.4'), (123 * 3600 + 11 * 60 + 15 + 0.400));
is(parse_timing('123:11:15,4'), (123 * 3600 + 11 * 60 + 15 + 0.400));
$timing = "123:11:15.45"; # invalid timecodes
$time = parse_timing($timing); is(parse_timing('123:60:15.45'), -1);
is($time, (123 * 3600 + 11 * 60 + 15 + 0.450)); is(parse_timing('123:11:65.45'), -1);
is(parse_timing('123:11:15.4500'), -1);
$timing = "123:11:15.4";
$time = parse_timing($timing); ## make_timing()
is($time, (123 * 3600 + 11 * 60 + 15 + 0.400)); my @ts = make_timing(8*3600 + 11*60 + 15 + 0.46);
is($ts[0], 8);
$timing = "123:11:15,4"; is($ts[1], 11);
$time = parse_timing($timing); is($ts[2], 15);
is($time, (123 * 3600 + 11 * 60 + 15 + 0.400)); is($ts[3], 460);
$timing = "123:60:15.45";
$time = parse_timing($timing);
is($time, -1);
$timing = "123:11:65.45";
$time = parse_timing($timing);
is($time, -1);
$timing = "123:11:15.4500";
$time = parse_timing($timing);
is($time, -1);
my ($hrs, $min, $sec, $msec);
($hrs, $min, $sec, $msec) = make_timing(8 * 3600 + 11 * 60 + 15 + 0.46);
is($hrs, 8);
is($min, 11);
is($sec, 15);
is($msec, 460);

Loading…
Cancel
Save