Sha256: 501557570a3e6ca988f5fcc56268a86d28aabb376578c9aa1b4288bddb76328b

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "test_helper"

class DiffFileTest < Minitest::Test
  def setup
    @file = GitDiff::File.new
  end

  def test_from_string_with_a_diff
    file = GitDiff::File.from_string "diff --git"

    refute_nil file
    assert_instance_of GitDiff::File, file
  end

  def test_from_string_without_a_diff
    file = GitDiff::File.from_string ""

    assert_nil file
  end

  def test_blob_data_is_correctly_extracted
    @file << "index 033b446..0e2d140 100644"

    assert_equal "033b446", @file.a_blob
    assert_equal "0e2d140", @file.b_blob
  end

  def test_mode_data_is_correctly_extracted
    @file << "index 033b446..0e2d140 100644"

    assert_equal "100644", @file.b_mode
  end

  def test_paths_are_correctly_extracted
    @file << "--- a/lib/grit/repo.rb"
    @file << "+++ b/lib/grit/repo.rb"

    assert_equal "lib/grit/repo.rb", @file.a_path
    assert_equal "lib/grit/repo.rb", @file.b_path
  end

  def test_appending_a_hunk
    @file << "@@ -180,7 +180,7 @@ module Grit"
    @file << "       io = StringIO.new(text)"
    @file << "       objects = []"
    @file << "       while line = io.gets"
    @file << "-        sha, type, size = line.split(' ', 3)"
    @file << "+        sha, type, size = line.split(' ', 3) #wut"
    @file << "         parser = BATCH_PARSERS[type]"
    @file << "         if type == 'missing' || !parser"
    @file << "           io.seek(size.to_i + 1, IO::SEEK_CUR)"

    assert_equal 1, @file.hunks.count
    assert_equal 8, @file.stats.number_of_lines
    assert_equal 1, @file.stats.number_of_additions
    assert_equal 1, @file.stats.number_of_deletions
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_diff-0.4.3 test/file_test.rb