Sha256: 60bfc8a01e35b968b3dddfdd23c942ad2bec7f95416f0b8870499f66c8a3a7a4

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe 'Diff::LCS Issues' do
  include Diff::LCS::SpecHelper::Matchers

  describe 'issue #1' do
    shared_examples 'handles simple diffs' do |s1, s2, forward_diff|
      before do
        @diff_s1_s2 = Diff::LCS.diff(s1, s2)
      end

      it 'creates the correct diff' do
        expect(change_diff(forward_diff)).to eq(@diff_s1_s2)
      end

      it 'creates the correct patch s1->s2' do
        expect(Diff::LCS.patch(s1, @diff_s1_s2)).to eq(s2)
      end

      it 'creates the correct patch s2->s1' do
        expect(Diff::LCS.patch(s2, @diff_s1_s2)).to eq(s1)
      end
    end

    describe 'string' do
      it_has_behavior 'handles simple diffs', 'aX', 'bXaX', [
        [
          ['+', 0, 'b'],
          ['+', 1, 'X']
        ]
      ]
      it_has_behavior 'handles simple diffs', 'bXaX', 'aX', [
        [
          ['-', 0, 'b'],
          ['-', 1, 'X']
        ]
      ]
    end

    describe 'array' do
      it_has_behavior 'handles simple diffs', %w(a X), %w(b X a X), [
        [
          ['+', 0, 'b'],
          ['+', 1, 'X']
        ]
      ]
      it_has_behavior 'handles simple diffs', %w(b X a X), %w(a X), [
        [
          ['-', 0, 'b'],
          ['-', 1, 'X']
        ]
      ]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
diff-lcs-1.4 spec/issues_spec.rb