diff options
| author | syeopite <syeopite@syeopite.dev> | 2023-08-24 14:58:50 -0700 |
|---|---|---|
| committer | syeopite <syeopite@syeopite.dev> | 2023-09-23 09:20:20 -0400 |
| commit | 54fa59cbb0ae90a54136522c944410e2d18c234b (patch) | |
| tree | fed46db2f98281973186fffcea1298e5b2d84cc2 /spec/helpers | |
| parent | bb14f794969f62582917a39c2dd57bf92fa146a7 (diff) | |
| download | invidious-54fa59cbb0ae90a54136522c944410e2d18c234b.tar.gz invidious-54fa59cbb0ae90a54136522c944410e2d18c234b.tar.bz2 invidious-54fa59cbb0ae90a54136522c944410e2d18c234b.zip | |
Add method to construct WebVTT files
Similar to JSON.Build
Diffstat (limited to 'spec/helpers')
| -rw-r--r-- | spec/helpers/vtt/builder_spec.cr | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/helpers/vtt/builder_spec.cr b/spec/helpers/vtt/builder_spec.cr new file mode 100644 index 00000000..69303bab --- /dev/null +++ b/spec/helpers/vtt/builder_spec.cr @@ -0,0 +1,64 @@ +require "../../spec_helper.cr" + +MockLines = [ + { + "start_time": Time::Span.new(seconds: 1), + "end_time": Time::Span.new(seconds: 2), + "text": "Line 1", + }, + + { + "start_time": Time::Span.new(seconds: 2), + "end_time": Time::Span.new(seconds: 3), + "text": "Line 2", + }, +] + +Spectator.describe "WebVTT::Builder" do + it "correctly builds a vtt file" do + result = WebVTT.build do |vtt| + MockLines.each do |line| + vtt.line(line["start_time"], line["end_time"], line["text"]) + end + end + + expect(result).to eq([ + "WEBVTT", + "", + "00:00:01.000 --> 00:00:02.000", + "Line 1", + "", + "00:00:02.000 --> 00:00:03.000", + "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| + MockLines.each do |line| + vtt.line(line["start_time"], line["end_time"], line["text"]) + end + end + + expect(result).to eq([ + "WEBVTT", + "Kind: captions", + "Language: en", + "", + "00:00:01.000 --> 00:00:02.000", + "Line 1", + "", + "00:00:02.000 --> 00:00:03.000", + "Line 2", + "", + "", + ].join('\n')) + end +end |
