Browse Source

* t/utils-timing.t : refactoring

master
Alex 'AdUser' Z 7 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);
my ($timing, $time);
$timing = "123:11:15.459";
$time = parse_timing($timing);
is($time, (123 * 3600 + 11 * 60 + 15 + 0.459));
$timing = "123:11:15.45";
$time = parse_timing($timing);
is($time, (123 * 3600 + 11 * 60 + 15 + 0.450));
$timing = "123:11:15.4";
$time = parse_timing($timing);
is($time, (123 * 3600 + 11 * 60 + 15 + 0.400));
$timing = "123:11:15,4";
$time = parse_timing($timing);
is($time, (123 * 3600 + 11 * 60 + 15 + 0.400));
$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);
## parse_timing()
# valid timecodes
is(parse_timing('123:11:15.459'), (123 * 3600 + 11 * 60 + 15 + 0.459));
is(parse_timing('123:11:15.45'), (123 * 3600 + 11 * 60 + 15 + 0.450));
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));
# invalid timecodes
is(parse_timing('123:60:15.45'), -1);
is(parse_timing('123:11:65.45'), -1);
is(parse_timing('123:11:15.4500'), -1);
## make_timing()
my @ts = make_timing(8*3600 + 11*60 + 15 + 0.46);
is($ts[0], 8);
is($ts[1], 11);
is($ts[2], 15);
is($ts[3], 460);

Loading…
Cancel
Save