Browse Source

+ t/format-smi.t

master
Alex 'AdUser' Z 6 years ago
parent
commit
612c3ec316
  1. 85
      t/format-smi.t

85
t/format-smi.t

@ -0,0 +1,85 @@
use strict;
use warnings;
use Test::More tests => 14;
use Subtitle::Format::SMI;
my $smi = Subtitle::Format::SMI->new(debug => 1);
is(ref $smi, 'Subtitle::Format::SMI');
can_ok($smi, qw(new parse build));
my $sample = <<"EOF";
<SAMI>
<HEAD>
<TITLE>Title</TITLE>
<SAMIPARAM><!-- Length: 63 --></SAMIPARAM>
<STYLE Type="text/css"><!--
P {margin-left: 2pt; margin-right: 2pt; font-size: 12pt; }
.SCC {Name: 'Some lang'; lang: ru; }
--></STYLE>
</HEAD>
<BODY>
<TABLE>
<SYNC START=12>
<P Class=SCC>
First event<BR>
Another line
<SYNC START=20>
<P Class=SCC>
&nbsp;
<SYNC START=30>
<P Class=SCC>Second event
<SYNC START=40>
<P Class=SCC>&nbsp;
<SYNC START=50>
<P Class=SCC>No 'empty' event to hide this<br>
show till end-of-file
</TABLE>
</BODY>
</SAMI>
EOF
my $cnt = $smi->from_string($sample);
is($cnt, 3);
is($smi->{style}, "P {margin-left: 2pt; margin-right: 2pt; font-size: 12pt; }\n.SCC {Name: 'Some lang'; lang: ru; }");
my @events = $smi->events;
is($events[0]->t_start, 12);
is($events[0]->t_end, 20);
is($events[0]->text, "First event\\nAnother line");
is($events[1]->t_start, 30);
is($events[1]->t_end, 40);
is($events[1]->text, "Second event");
is($events[2]->t_start, 50);
is($events[2]->t_end, 63); # from samiparam/length
is($events[2]->text, "No 'empty' event to hide this\\nshow till end-of-file");
$sample = <<"EOF";
<sami>
<head>
<title>Title</title>
<samiparam><!-- Length: 63 --></samiparam>
<style type="text/css"><!--
P {margin-left: 2pt; margin-right: 2pt; font-size: 12pt; }
.SCC {Name: 'Some lang'; lang: ru; }
--></style>
</head>
<body>
<table>
<sync start=12><p class=scc>First event<br>Another line</p></sync>
<sync start=20><p>&nbsp;</p></sync>
<sync start=30><p class=scc>Second event</p></sync>
<sync start=40><p>&nbsp;</p></sync>
<sync start=50><p class=scc>No 'empty' event to hide this<br>show till end-of-file</p></sync>
<sync start=63><p>&nbsp;</p></sync>
</table>
</body>
</sami>
EOF
is($smi->build, $sample);
use File::Slurp;
write_file('1.txt', $smi->build);
write_file('2.txt', $sample);
exit 0;
Loading…
Cancel
Save