From e445187fd50ee2c571f97297841ede998a814e88 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 23 Jul 2018 23:15:02 +1000 Subject: [PATCH] * t/utils-timing.t : refactoring --- t/utils-timing.t | 54 +++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/t/utils-timing.t b/t/utils-timing.t index 80f61c8..7f8a33b 100644 --- a/t/utils-timing.t +++ b/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);