You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

use strict;
use warnings;
use Test::More tests => 21;
use Subtitle::Utils qw(:timing);
## 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);
## parse_timeshift()
is(parse_timeshift('1'), +1.0);
is(parse_timeshift('-1.2'), -1.2);
is(parse_timeshift('+2:15'), +135.0);
is(parse_timeshift('+03:07.35'), +187.35);
is(parse_timeshift('4:05:17.312'), 14717.312);
# invalid timecodes
is(parse_timeshift('o.17'), undef);
is(parse_timeshift('-.05'), undef);
is(parse_timeshift('1:60'), undef);
is(parse_timeshift('57.4321'), undef);
is(parse_timeshift('1:62:03'), undef);
## 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);