2023-08-25 03:28:50 +05:30
|
|
|
require "../../spec_helper.cr"
|
|
|
|
|
2024-01-31 04:55:45 +05:30
|
|
|
MockLines = ["Line 1", "Line 2"]
|
|
|
|
MockLinesWithEscapableCharacter = ["<Line 1>", "&Line 2>", '\u200E' + "Line\u200F 3", "\u00A0Line 4"]
|
2023-08-25 03:28:50 +05:30
|
|
|
|
|
|
|
Spectator.describe "WebVTT::Builder" do
|
|
|
|
it "correctly builds a vtt file" do
|
|
|
|
result = WebVTT.build do |vtt|
|
2024-01-31 04:55:45 +05:30
|
|
|
2.times do |i|
|
|
|
|
vtt.cue(
|
|
|
|
Time::Span.new(seconds: i),
|
|
|
|
Time::Span.new(seconds: i + 1),
|
|
|
|
MockLines[i]
|
|
|
|
)
|
2023-08-25 03:28:50 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to eq([
|
|
|
|
"WEBVTT",
|
|
|
|
"",
|
2024-01-31 04:55:45 +05:30
|
|
|
"00:00:00.000 --> 00:00:01.000",
|
2023-08-25 03:28:50 +05:30
|
|
|
"Line 1",
|
|
|
|
"",
|
2024-01-31 04:55:45 +05:30
|
|
|
"00:00:01.000 --> 00:00:02.000",
|
2023-08-25 03:28:50 +05:30
|
|
|
"Line 2",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
].join('\n'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "correctly builds a vtt file with setting fields" do
|
|
|
|
setting_fields = {
|
|
|
|
"Kind" => "captions",
|
|
|
|
"Language" => "en",
|
|
|
|
}
|
|
|
|
|
|
|
|
result = WebVTT.build(setting_fields) do |vtt|
|
2024-01-31 04:55:45 +05:30
|
|
|
2.times do |i|
|
|
|
|
vtt.cue(
|
|
|
|
Time::Span.new(seconds: i),
|
|
|
|
Time::Span.new(seconds: i + 1),
|
|
|
|
MockLines[i]
|
|
|
|
)
|
2023-08-25 03:28:50 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to eq([
|
|
|
|
"WEBVTT",
|
|
|
|
"Kind: captions",
|
|
|
|
"Language: en",
|
|
|
|
"",
|
2024-01-31 04:55:45 +05:30
|
|
|
"00:00:00.000 --> 00:00:01.000",
|
2023-08-25 03:28:50 +05:30
|
|
|
"Line 1",
|
|
|
|
"",
|
2024-01-31 04:55:45 +05:30
|
|
|
"00:00:01.000 --> 00:00:02.000",
|
2023-08-25 03:28:50 +05:30
|
|
|
"Line 2",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
].join('\n'))
|
|
|
|
end
|
2024-01-31 04:55:45 +05:30
|
|
|
|
|
|
|
it "properly escapes characters" do
|
|
|
|
result = WebVTT.build do |vtt|
|
|
|
|
4.times do |i|
|
|
|
|
vtt.cue(Time::Span.new(seconds: i), Time::Span.new(seconds: i + 1), MockLinesWithEscapableCharacter[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to eq([
|
|
|
|
"WEBVTT",
|
|
|
|
"",
|
|
|
|
"00:00:00.000 --> 00:00:01.000",
|
|
|
|
"<Line 1>",
|
|
|
|
"",
|
|
|
|
"00:00:01.000 --> 00:00:02.000",
|
|
|
|
"&Line 2>",
|
|
|
|
"",
|
|
|
|
"00:00:02.000 --> 00:00:03.000",
|
|
|
|
"‎Line‏ 3",
|
|
|
|
"",
|
|
|
|
"00:00:03.000 --> 00:00:04.000",
|
|
|
|
" Line 4",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
].join('\n'))
|
|
|
|
end
|
2023-08-25 03:28:50 +05:30
|
|
|
end
|