|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Test::More tests => 31;
|
|
|
|
|
|
|
|
use Subtitle::Format::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::Format::SSA::Event->new(type => 'ssa');
|
|
|
|
can_ok($event, qw(new parse t_start t_end text));
|
|
|
|
$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::Format::SSA::Event->new(type => '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::Format::SSA::Event->new(type => '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::Format::SSA::Event->new(type => '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;
|