Browse Source

+ t/format-ssa-event.t

master
Alex 'AdUser' Z 8 years ago
parent
commit
e08f87a700
  1. 60
      t/format-ssa-event.t

60
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;
Loading…
Cancel
Save