<commit_before>require 'spec_helper'

module FFSplitter
  describe FFMpeg do
    let(:ffmpeg){ FFMpeg.new(options) }
    let(:runner) { double("runner") }
    before { ffmpeg.runner = runner }

    describe "#encode" do
      let(:options) { {filename: "test.mp4"} }
      let(:chapter_list) { ChapterList.new }
      let(:chapter1) { Chapter.new(title: "Chapter 1") }
      let(:chapter2) { Chapter.new(title: "Chapter 2") }

      context "with a single chapter" do
        before { chapter_list.add(chapter1) }
        it "encodes the chapter" do
          expect(runner).to receive(:run).with("#{ffmpeg.chapter_command(chapter1)}")
          ffmpeg.encode(chapter_list)
        end
      end

      context "with multiple chapters" do
        before do
          chapter_list.add(chapter1)
          chapter_list.add(chapter2)
        end
        it "encodes the chapters with a single ffmpeg command" do
          commands = "#{ffmpeg.chapter_command(chapter1)} && #{ffmpeg.chapter_command(chapter2)}"
          expect(runner).to receive(:run).once.with("#{commands}")
          ffmpeg.encode(chapter_list)
        end
      end
    end

    describe "#chapter_command" do

      let(:chapter) { Chapter.new(start_frames: 10, end_frames: 30, timebase: 1, title: "test title") }
      let(:command) { ffmpeg.chapter_command(chapter) }
      context "without an output directory" do
        let(:options) { {filename: "test.mp4", output_extension: ".m4v"} }
        it "creates a chapter command" do
          expect(command).to match("-ss #{chapter.start_time}")
          expect(command).to match("-i 'test.mp4'")
          expect(command).to match("-t #{chapter.duration}")
          expect(command).to match("test title.m4v")
          expect(command).to match(FFSplitter::FFMpeg::CODEC_OPTIONS)
          expect(command).to match("#{File.expand_path(chapter.filename)}")
        end
      end

      context "with an output directory" do<commit_msg>Whitespace<commit_after>require 'spec_helper'

module FFSplitter
  describe FFMpeg do
    let(:ffmpeg){ FFMpeg.new(options) }
    let(:runner) { double("runner") }
    before { ffmpeg.runner = runner }

    describe "#encode" do
      let(:options) { {filename: "test.mp4"} }
      let(:chapter_list) { ChapterList.new }
      let(:chapter1) { Chapter.new(title: "Chapter 1") }
      let(:chapter2) { Chapter.new(title: "Chapter 2") }

      context "with a single chapter" do
        before { chapter_list.add(chapter1) }
        it "encodes the chapter" do
          expect(runner).to receive(:run).with("#{ffmpeg.chapter_command(chapter1)}")
          ffmpeg.encode(chapter_list)
        end
      end

      context "with multiple chapters" do
        before do
          chapter_list.add(chapter1)
          chapter_list.add(chapter2)
        end
        it "encodes the chapters with a single ffmpeg command" do
          commands = "#{ffmpeg.chapter_command(chapter1)} && #{ffmpeg.chapter_command(chapter2)}"
          expect(runner).to receive(:run).once.with("#{commands}")
          ffmpeg.encode(chapter_list)
        end
      end
    end

    describe "#chapter_command" do
      let(:chapter) { Chapter.new(start_frames: 10, end_frames: 30, timebase: 1, title: "test title") }
      let(:command) { ffmpeg.chapter_command(chapter) }
      context "without an output directory" do
        let(:options) { {filename: "test.mp4", output_extension: ".m4v"} }
        it "creates a chapter command" do
          expect(command).to match("-ss #{chapter.start_time}")
          expect(command).to match("-i 'test.mp4'")
          expect(command).to match("-t #{chapter.duration}")
          expect(command).to match("test title.m4v")
          expect(command).to match(FFSplitter::FFMpeg::CODEC_OPTIONS)
          expect(command).to match("#{File.expand_path(chapter.filename)}")
        end
      end

      context "with an output directory" do
{'fraction_non_alphanumeric': 0.1319693094629156, 'fraction_numerical': 0.010230179028132993, 'mean_word_length': 2.797087378640777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2054465', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1178, 'n_words': 265}