From e08f87a700f0b8ff29cd26fc8b155934f34a23b1 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Sat, 2 Jul 2016 21:39:02 +1000 Subject: [PATCH] + t/format-ssa-event.t --- t/format-ssa-event.t | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 t/format-ssa-event.t diff --git a/t/format-ssa-event.t b/t/format-ssa-event.t new file mode 100644 index 0000000..2702106 --- /dev/null +++ b/t/format-ssa-event.t @@ -0,0 +1,60 @@ +use strict; +use warnings; + +use Test::More tests => 30; + +use Subtitle::SSA::Event; + +my ($fields, @fields, $format, $sample, $event, $output); + +# SSA format line +$format = 'Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text'; +@fields = qw(marked start end style name marginl marginr marginv effect text); +$event = Subtitle::SSA::Event->new(version => 'ssa'); +$fields = $event->parse_format_line($format); +is(ref $fields, 'ARRAY'); +is_deeply($fields, \@fields); + +# ASS format line +$format = 'Format:Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text'; +@fields = qw(layer start end style name marginl marginr marginv effect text); +$event = Subtitle::SSA::Event->new(version => 'ass'); +$fields = $event->parse_format_line($format); +is(ref $fields, 'ARRAY'); +is_deeply($fields, \@fields); + +$sample = 'Dialogue: Marked=0,0:01:50.15,0:01:54.15,Main,,0000,0000,0050,,Наступило новое утро'; +$event = Subtitle::SSA::Event->new(version => 'ssa'); +ok($event->parse($sample), "SSA event parsing test"); +is($event->{marked} => 'Marked=0'); +is($event->{start} => 110.15); +is($event->{end} => 114.15); +is($event->{style} => 'Main'); +is($event->{name} => ''); +is($event->{marginl} => 0); +is($event->{marginr} => 0); +is($event->{marginv} => 50); +is($event->{effect} => ''); +is($event->{text} => 'Наступило новое утро'); + +ok($output = $event->to_string(), 'converting SSA event to string'); +is($output => $sample); + +$sample = 'Dialogue: 1,0:01:06.68,0:01:07.49,text three,,0000,0000,0000,,Я счастлив.'; +$event = Subtitle::SSA::Event->new(version => 'ass'); +ok($event->parse($sample), "ASS event parsing test"); +is($event->{layer} => 1); +is($event->{start} => 66.68); +is($event->{end} => 67.49); +is($event->{style} => 'text three'); +is($event->{name} => ''); +is($event->{marginl} => 0); +is($event->{marginr} => 0); +is($event->{marginv} => 0); +is($event->{effect} => ''); +is($event->{text} => 'Я счастлив.'); + +ok($output = $event->to_string(), 'converting ASS event to string'); +is($output => $sample); + +exit 0;