diff-lcs-1.3/0000755000004100000410000000000013041652267013102 5ustar www-datawww-datadiff-lcs-1.3/Rakefile0000644000004100000410000000272313041652267014553 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'rubygems' require 'rspec' require 'hoe' Hoe.plugin :bundler Hoe.plugin :doofus Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS'] Hoe.plugin :gemspec2 Hoe.plugin :git Hoe.plugin :travis spec = Hoe.spec 'diff-lcs' do developer('Austin Ziegler', 'halostatue@gmail.com') require_ruby_version '>= 1.8' self.history_file = 'History.md' self.readme_file = 'README.rdoc' self.licenses = [ 'MIT', 'Artistic-2.0', 'GPL-2.0+' ] extra_dev_deps << ['hoe-doofus', '~> 1.0'] extra_dev_deps << ['hoe-gemspec2', '~> 1.1'] extra_dev_deps << ['hoe-git', '~> 1.6'] extra_dev_deps << ['hoe-rubygems', '~> 1.0'] extra_dev_deps << ['hoe-travis', '~> 1.2'] extra_dev_deps << ['rspec', '>= 2.0', '< 4'] extra_dev_deps << ['rake', '>= 10.0', '< 12'] extra_dev_deps << ['rdoc', '>= 0'] end unless Rake::Task.task_defined? :test task :test => :spec Rake::Task['travis'].prerequisites.replace(%w(spec)) end if RUBY_VERSION >= '2.0' && RUBY_ENGINE == 'ruby' namespace :spec do task :coveralls do if ENV['CI'] or ENV['TRAVIS'] ENV['COVERALLS'] = 'yes' Rake::Task['spec'].execute else Rake::Task['spec:coverage'].execute end end desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed." task :coverage do ENV['COVERAGE'] = 'yes' Rake::Task['spec'].execute end end # Rake::Task['travis'].prerequisites.replace(%w(spec:coveralls)) end diff-lcs-1.3/bin/0000755000004100000410000000000013041652267013652 5ustar www-datawww-datadiff-lcs-1.3/bin/ldiff0000755000004100000410000000013013041652267014656 0ustar www-datawww-data#!ruby -w require 'diff/lcs' require 'diff/lcs/ldiff' exit Diff::LCS::Ldiff.run(ARGV) diff-lcs-1.3/bin/htmldiff0000755000004100000410000000121013041652267015367 0ustar www-datawww-data#!ruby -w require 'diff/lcs' require 'diff/lcs/htmldiff' begin require 'text/format' rescue LoadError Diff::LCS::HTMLDiff.can_expand_tabs = false end if ARGV.size < 2 or ARGV.size > 3 $stderr.puts "usage: #{File.basename($0)} old new [output.html]" $stderr.puts " #{File.basename($0)} old new > output.html" exit 127 end left = IO.read(ARGV[0]).split($/) right = IO.read(ARGV[1]).split($/) options = { :title => "diff #{ARGV[0]} #{ARGV[1]}" } htmldiff = Diff::LCS::HTMLDiff.new(left, right, options) if ARGV[2] File.open(ARGV[2], "w") do |f| htmldiff.options[:output] = f htmldiff.run end else htmldiff.run end diff-lcs-1.3/Manifest.txt0000644000004100000410000000127013041652267015411 0ustar www-datawww-data.rspec Code-of-Conduct.md Contributing.md History.md License.md Manifest.txt README.rdoc Rakefile autotest/discover.rb bin/htmldiff bin/ldiff docs/COPYING.txt docs/artistic.txt lib/diff-lcs.rb lib/diff/lcs.rb lib/diff/lcs/array.rb lib/diff/lcs/block.rb lib/diff/lcs/callbacks.rb lib/diff/lcs/change.rb lib/diff/lcs/htmldiff.rb lib/diff/lcs/hunk.rb lib/diff/lcs/internals.rb lib/diff/lcs/ldiff.rb lib/diff/lcs/string.rb spec/change_spec.rb spec/diff_spec.rb spec/fixtures/ds1.csv spec/fixtures/ds2.csv spec/hunk_spec.rb spec/issues_spec.rb spec/lcs_spec.rb spec/ldiff_spec.rb spec/patch_spec.rb spec/sdiff_spec.rb spec/spec_helper.rb spec/traverse_balanced_spec.rb spec/traverse_sequences_spec.rb diff-lcs-1.3/.rspec0000644000004100000410000000001113041652267014207 0ustar www-datawww-data--colour diff-lcs-1.3/spec/0000755000004100000410000000000013041652267014034 5ustar www-datawww-datadiff-lcs-1.3/spec/sdiff_spec.rb0000644000004100000410000001250513041652267016471 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe "Diff::LCS.sdiff" do include Diff::LCS::SpecHelper::Matchers shared_examples "compare sequences correctly" do it "compares s1 -> s2 correctly" do expect(Diff::LCS.sdiff(s1, s2)).to eq(context_diff(result)) end it "compares s2 -> s1 correctly" do expect(Diff::LCS.sdiff(s2, s1)).to eq(context_diff(reverse_sdiff(result))) end end describe "using seq1 & seq2" do let(:s1) { seq1 } let(:s2) { seq2 } let(:result) { correct_forward_sdiff } it_has_behavior "compare sequences correctly" end describe "using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)" do let(:s1) { %w(abc def yyy xxx ghi jkl) } let(:s2) { %w(abc dxf xxx ghi jkl) } let(:result) { [ [ '=', [ 0, 'abc' ], [ 0, 'abc' ] ], [ '!', [ 1, 'def' ], [ 1, 'dxf' ] ], [ '-', [ 2, 'yyy' ], [ 2, nil ] ], [ '=', [ 3, 'xxx' ], [ 2, 'xxx' ] ], [ '=', [ 4, 'ghi' ], [ 3, 'ghi' ] ], [ '=', [ 5, 'jkl' ], [ 4, 'jkl' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a b c d e) & %w(a e)" do let(:s1) { %w(a b c d e) } let(:s2) { %w(a e) } let(:result) { [ [ '=', [ 0, 'a' ], [ 0, 'a' ] ], [ '-', [ 1, 'b' ], [ 1, nil ] ], [ '-', [ 2, 'c' ], [ 1, nil ] ], [ '-', [ 3, 'd' ], [ 1, nil ] ], [ '=', [ 4, 'e' ], [ 1, 'e' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a e) & %w(a b c d e)" do let(:s1) { %w(a e) } let(:s2) { %w(a b c d e) } let(:result) { [ [ '=', [ 0, 'a' ], [ 0, 'a' ] ], [ '+', [ 1, nil ], [ 1, 'b' ] ], [ '+', [ 1, nil ], [ 2, 'c' ] ], [ '+', [ 1, nil ], [ 3, 'd' ] ], [ '=', [ 1, 'e' ], [ 4, 'e' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(v x a e) & %w(w y a b c d e)" do let(:s1) { %w(v x a e) } let(:s2) { %w(w y a b c d e) } let(:result) { [ [ '!', [ 0, 'v' ], [ 0, 'w' ] ], [ '!', [ 1, 'x' ], [ 1, 'y' ] ], [ '=', [ 2, 'a' ], [ 2, 'a' ] ], [ '+', [ 3, nil ], [ 3, 'b' ] ], [ '+', [ 3, nil ], [ 4, 'c' ] ], [ '+', [ 3, nil ], [ 5, 'd' ] ], [ '=', [ 3, 'e' ], [ 6, 'e' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(x a e) & %w(a b c d e)" do let(:s1) { %w(x a e) } let(:s2) { %w(a b c d e) } let(:result) { [ [ '-', [ 0, 'x' ], [ 0, nil ] ], [ '=', [ 1, 'a' ], [ 0, 'a' ] ], [ '+', [ 2, nil ], [ 1, 'b' ] ], [ '+', [ 2, nil ], [ 2, 'c' ] ], [ '+', [ 2, nil ], [ 3, 'd' ] ], [ '=', [ 2, 'e' ], [ 4, 'e' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a e) & %w(x a b c d e)" do let(:s1) { %w(a e) } let(:s2) { %w(x a b c d e) } let(:result) { [ [ '+', [ 0, nil ], [ 0, 'x' ] ], [ '=', [ 0, 'a' ], [ 1, 'a' ] ], [ '+', [ 1, nil ], [ 2, 'b' ] ], [ '+', [ 1, nil ], [ 3, 'c' ] ], [ '+', [ 1, nil ], [ 4, 'd' ] ], [ '=', [ 1, 'e' ], [ 5, 'e' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a e v) & %w(x a b c d e w x)" do let(:s1) { %w(a e v) } let(:s2) { %w(x a b c d e w x) } let(:result) { [ [ '+', [ 0, nil ], [ 0, 'x' ] ], [ '=', [ 0, 'a' ], [ 1, 'a' ] ], [ '+', [ 1, nil ], [ 2, 'b' ] ], [ '+', [ 1, nil ], [ 3, 'c' ] ], [ '+', [ 1, nil ], [ 4, 'd' ] ], [ '=', [ 1, 'e' ], [ 5, 'e' ] ], [ '!', [ 2, 'v' ], [ 6, 'w' ] ], [ '+', [ 3, nil ], [ 7, 'x' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w() & %w(a b c)" do let(:s1) { %w() } let(:s2) { %w(a b c) } let(:result) { [ [ '+', [ 0, nil ], [ 0, 'a' ] ], [ '+', [ 0, nil ], [ 1, 'b' ] ], [ '+', [ 0, nil ], [ 2, 'c' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a b c) & %w(1)" do let(:s1) { %w(a b c) } let(:s2) { %w(1) } let(:result) { [ [ '!', [ 0, 'a' ], [ 0, '1' ] ], [ '-', [ 1, 'b' ], [ 1, nil ] ], [ '-', [ 2, 'c' ], [ 1, nil ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(a b c) & %w(c)" do let(:s1) { %w(a b c) } let(:s2) { %w(c) } let(:result) { [ [ '-', [ 0, 'a' ], [ 0, nil ] ], [ '-', [ 1, 'b' ], [ 0, nil ] ], [ '=', [ 2, 'c' ], [ 0, 'c' ] ] ] } it_has_behavior "compare sequences correctly" end describe "using %w(abcd efgh ijkl mnop) & []" do let(:s1) { %w(abcd efgh ijkl mnop) } let(:s2) { [] } let(:result) { [ [ '-', [ 0, 'abcd' ], [ 0, nil ] ], [ '-', [ 1, 'efgh' ], [ 0, nil ] ], [ '-', [ 2, 'ijkl' ], [ 0, nil ] ], [ '-', [ 3, 'mnop' ], [ 0, nil ] ] ] } it_has_behavior "compare sequences correctly" end describe "using [[1,2]] & []" do let(:s1) { [ [ 1, 2 ] ] } let(:s2) { [] } let(:result) { [ [ '-', [ 0, [ 1, 2 ] ], [ 0, nil ] ] ] } it_has_behavior "compare sequences correctly" end end diff-lcs-1.3/spec/traverse_balanced_spec.rb0000644000004100000410000001634113041652267021044 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe "Diff::LCS.traverse_balanced" do include Diff::LCS::SpecHelper::Matchers shared_examples "with a #change callback" do |s1, s2, result| it "traverses s1 -> s2 correctly" do traversal = balanced_traversal(s1, s2, :balanced_callback) expect(traversal.result).to eq(result) end it "traverses s2 -> s1 correctly" do traversal = balanced_traversal(s2, s1, :balanced_callback) expect(traversal.result).to eq(balanced_reverse(result)) end end shared_examples "without a #change callback" do |s1, s2, result| it "traverses s1 -> s2 correctly" do traversal = balanced_traversal(s1, s2, :balanced_callback_no_change) expect(traversal.result).to eq(map_to_no_change(result)) end it "traverses s2 -> s1 correctly" do traversal = balanced_traversal(s2, s1, :balanced_callback_no_change) expect(traversal.result).to eq(map_to_no_change(balanced_reverse(result))) end end describe "identical string sequences ('abc')" do s1 = s2 = "abc" result = [ [ '=', 0, 0 ], [ '=', 1, 1 ], [ '=', 2, 2 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "identical array sequences %w(a b c)" do s1 = s2 = %w(a b c) result = [ [ '=', 0, 0 ], [ '=', 1, 1 ], [ '=', 2, 2 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a b c) & %w(a x c)" do s1 = %w(a b c) s2 = %w(a x c) result = [ [ '=', 0, 0 ], [ '!', 1, 1 ], [ '=', 2, 2 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a x y c) & %w(a v w c)" do s1 = %w(a x y c) s2 = %w(a v w c) result = [ [ '=', 0, 0 ], [ '!', 1, 1 ], [ '!', 2, 2 ], [ '=', 3, 3 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(x y c) & %w(v w c)" do s1 = %w(x y c) s2 = %w(v w c) result = [ [ '!', 0, 0 ], [ '!', 1, 1 ], [ '=', 2, 2 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a x y z) & %w(b v w)" do s1 = %w(a x y z) s2 = %w(b v w) result = [ [ '!', 0, 0 ], [ '!', 1, 1 ], [ '!', 2, 2 ], [ '<', 3, 3 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a z) & %w(a)" do s1 = %w(a z) s2 = %w(a) result = [ [ '=', 0, 0 ], [ '<', 1, 1 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(z a) & %w(a)" do s1 = %w(z a) s2 = %w(a) result = [ [ '<', 0, 0 ], [ '=', 1, 0 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(a b c) & %w(x y z)" do s1 = %w(a b c) s2 = %w(x y z) result = [ [ '!', 0, 0 ], [ '!', 1, 1 ], [ '!', 2, 2 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "sequences %w(abcd efgh ijkl mnoopqrstuvwxyz) & []" do s1 = %w(abcd efgh ijkl mnopqrstuvwxyz) s2 = [] result = [ [ '<', 0, 0 ], [ '<', 1, 0 ], [ '<', 2, 0 ], [ '<', 3, 0 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(a b c) & %Q(a x c)" do s1 = %Q(a b c) s2 = %Q(a x c) result = [ [ '=', 0, 0 ], [ '=', 1, 1 ], [ '!', 2, 2 ], [ '=', 3, 3 ], [ '=', 4, 4 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(a x y c) & %Q(a v w c)" do s1 = %Q(a x y c) s2 = %Q(a v w c) result = [ [ '=', 0, 0 ], [ '=', 1, 1 ], [ '!', 2, 2 ], [ '=', 3, 3 ], [ '!', 4, 4 ], [ '=', 5, 5 ], [ '=', 6, 6 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(x y c) & %Q(v w c)" do s1 = %Q(x y c) s2 = %Q(v w c) result = [ [ '!', 0, 0 ], [ '=', 1, 1 ], [ '!', 2, 2 ], [ '=', 3, 3 ], [ '=', 4, 4 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(a x y z) & %Q(b v w)" do s1 = %Q(a x y z) s2 = %Q(b v w) result = [ [ '!', 0, 0 ], [ '=', 1, 1 ], [ '!', 2, 2 ], [ '=', 3, 3 ], [ '!', 4, 4 ], [ '<', 5, 5 ], [ '<', 6, 5 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(a z) & %Q(a)" do s1 = %Q(a z) s2 = %Q(a) result = [ [ '=', 0, 0 ], [ '<', 1, 1 ], [ '<', 2, 1 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(z a) & %Q(a)" do s1 = %Q(z a) s2 = %Q(a) result = [ [ '<', 0, 0 ], [ '<', 1, 0 ], [ '=', 2, 0 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(a b c) & %Q(x y z)" do s1 = %Q(a b c) s2 = %Q(x y z) result = [ [ '!', 0, 0 ], [ '=', 1, 1 ], [ '!', 2, 2 ], [ '=', 3, 3 ], [ '!', 4, 4 ] ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end describe "strings %Q(abcd efgh ijkl mnopqrstuvwxyz) & %Q()" do s1 = %Q(abcd efgh ijkl mnopqrstuvwxyz) s2 = "" result = [ [ '<', 0, 0 ], [ '<', 1, 0 ], [ '<', 2, 0 ], [ '<', 3, 0 ], [ '<', 4, 0 ], [ '<', 5, 0 ], [ '<', 6, 0 ], [ '<', 7, 0 ], [ '<', 8, 0 ], [ '<', 9, 0 ], [ '<', 10, 0 ], [ '<', 11, 0 ], [ '<', 12, 0 ], [ '<', 13, 0 ], [ '<', 14, 0 ], [ '<', 15, 0 ], [ '<', 16, 0 ], [ '<', 17, 0 ], [ '<', 18, 0 ], [ '<', 19, 0 ], [ '<', 20, 0 ], [ '<', 21, 0 ], [ '<', 22, 0 ], [ '<', 23, 0 ], [ '<', 24, 0 ], [ '<', 25, 0 ], [ '<', 26, 0 ], [ '<', 27, 0 ], [ '<', 28, 0 ], ] it_has_behavior "with a #change callback", s1, s2, result it_has_behavior "without a #change callback", s1, s2, result end end diff-lcs-1.3/spec/hunk_spec.rb0000644000004100000410000000367413041652267016352 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' if String.method_defined?(:encoding) require 'diff/lcs/hunk' describe Diff::LCS::Hunk do let(:old_data) { ["Tu avec carté {count} itém has".encode('UTF-16LE')] } let(:new_data) { ["Tu avec carte {count} item has".encode('UTF-16LE')] } let(:pieces) { Diff::LCS.diff old_data, new_data } let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) } it 'produces a unified diff from the two pieces' do expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp) @@ -1,2 +1,2 @@ -Tu avec carté {count} itém has +Tu avec carte {count} item has EOD expect(hunk.diff(:unified)).to eq(expected) end it 'produces a context diff from the two pieces' do expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp) *************** *** 1,2 **** !Tu avec carté {count} itém has --- 1,2 ---- !Tu avec carte {count} item has EOD expect(hunk.diff(:context)).to eq(expected) end it 'produces an old diff from the two pieces' do expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp) 1,2c1,2 < Tu avec carté {count} itém has --- > Tu avec carte {count} item has EOD expect(hunk.diff(:old)).to eq(expected) end it 'produces a reverse ed diff from the two pieces' do expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp) c1,2 Tu avec carte {count} item has . EOD expect(hunk.diff(:reverse_ed)).to eq(expected) end context 'with empty first data set' do let(:old_data) { [] } it 'produces a unified diff' do expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp) @@ -1 +1,2 @@ +Tu avec carte {count} item has EOD expect(hunk.diff(:unified)).to eq(expected) end end end end diff-lcs-1.3/spec/ldiff_spec.rb0000644000004100000410000000247213041652267016464 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe "Diff::LCS.diff" do include Diff::LCS::SpecHelper::Matchers it 'correctly diffs seq1 to seq2' do diff_s1_s2 = Diff::LCS.diff(seq1, seq2) expect(change_diff(correct_forward_diff)).to eq(diff_s1_s2) end it 'correctly diffs seq2 to seq1' do diff_s2_s1 = Diff::LCS.diff(seq2, seq1) expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1) end it 'correctly diffs against an empty sequence' do diff = Diff::LCS.diff(word_sequence, []) correct_diff = [ [ [ '-', 0, 'abcd' ], [ '-', 1, 'efgh' ], [ '-', 2, 'ijkl' ], [ '-', 3, 'mnopqrstuvwxyz' ] ] ] expect(change_diff(correct_diff)).to eq(diff) diff = Diff::LCS.diff([], word_sequence) correct_diff.each { |hunk| hunk.each { |change| change[0] = '+' } } expect(change_diff(correct_diff)).to eq(diff) end it "correctly diffs 'xx' and 'xaxb'" do left = 'xx' right = 'xaxb' expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right) end it "returns an empty diff with (hello, hello)" do expect(Diff::LCS.diff(hello, hello)).to eq([]) end it "returns an empty diff with (hello_ary, hello_ary)" do expect(Diff::LCS.diff(hello_ary, hello_ary)).to eq([]) end end diff-lcs-1.3/spec/change_spec.rb0000644000004100000410000000357513041652267016632 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe Diff::LCS::Change do describe "an add" do subject { described_class.new('+', 0, 'element') } it { should_not be_deleting } it { should be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a delete" do subject { described_class.new('-', 0, 'element') } it { should be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "an unchanged" do subject { described_class.new('=', 0, 'element') } it { should_not be_deleting } it { should_not be_adding } it { should be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a changed" do subject { described_class.new('!', 0, 'element') } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should be_changed } it { should_not be_finished_a } it { should_not be_finished_b } end describe "a finished_a" do subject { described_class.new('>', 0, 'element') } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should be_finished_a } it { should_not be_finished_b } end describe "a finished_b" do subject { described_class.new('<', 0, 'element') } it { should_not be_deleting } it { should_not be_adding } it { should_not be_unchanged } it { should_not be_changed } it { should_not be_finished_a } it { should be_finished_b } end end diff-lcs-1.3/spec/spec_helper.rb0000644000004100000410000001507013041652267016655 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'rubygems' require 'pathname' require 'psych' if ENV['COVERALLS'] require 'coveralls' Coveralls.wear! elsif ENV['COVERAGE'] require 'simplecov' def require_do(resource, &block) require resource block.call rescue LoadError nil end formatters = [ SimpleCov::Formatter::HTMLFormatter ] require_do('simplecov-rcov') { formatters << SimpleCov::Formatter::RcovFormatter } require_do('simplecov-vim/formatter') { formatters << SimpleCov::Formatter::VimFormatter } require_do('simplecov-sublime-ruby-coverage') { formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter } SimpleCov.start do formatter SimpleCov::Formatter::MultiFormatter[*formatters] end end file = Pathname.new(__FILE__).expand_path path = file.parent parent = path.parent $:.unshift parent.join('lib') require 'diff-lcs' module Diff::LCS::SpecHelper def hello "hello" end def hello_ary %W(h e l l o) end def seq1 %w(a b c e h j l m n p) end def skipped_seq1 %w(a h n p) end def seq2 %w(b c d e f j k l m r s t) end def skipped_seq2 %w(d f k r s t) end def word_sequence %w(abcd efgh ijkl mnopqrstuvwxyz) end def correct_lcs %w(b c e j l m) end def correct_forward_diff [ [ [ '-', 0, 'a' ] ], [ [ '+', 2, 'd' ] ], [ [ '-', 4, 'h' ], [ '+', 4, 'f' ] ], [ [ '+', 6, 'k' ] ], [ [ '-', 8, 'n' ], [ '-', 9, 'p' ], [ '+', 9, 'r' ], [ '+', 10, 's' ], [ '+', 11, 't' ] ] ] end def correct_backward_diff [ [ [ '+', 0, 'a' ] ], [ [ '-', 2, 'd' ] ], [ [ '-', 4, 'f' ], [ '+', 4, 'h' ] ], [ [ '-', 6, 'k' ] ], [ [ '-', 9, 'r' ], [ '-', 10, 's' ], [ '+', 8, 'n' ], [ '-', 11, 't' ], [ '+', 9, 'p' ] ] ] end def correct_forward_sdiff [ [ '-', [ 0, 'a' ], [ 0, nil ] ], [ '=', [ 1, 'b' ], [ 0, 'b' ] ], [ '=', [ 2, 'c' ], [ 1, 'c' ] ], [ '+', [ 3, nil ], [ 2, 'd' ] ], [ '=', [ 3, 'e' ], [ 3, 'e' ] ], [ '!', [ 4, 'h' ], [ 4, 'f' ] ], [ '=', [ 5, 'j' ], [ 5, 'j' ] ], [ '+', [ 6, nil ], [ 6, 'k' ] ], [ '=', [ 6, 'l' ], [ 7, 'l' ] ], [ '=', [ 7, 'm' ], [ 8, 'm' ] ], [ '!', [ 8, 'n' ], [ 9, 'r' ] ], [ '!', [ 9, 'p' ], [ 10, 's' ] ], [ '+', [ 10, nil ], [ 11, 't' ] ] ] end def reverse_sdiff(forward_sdiff) forward_sdiff.map { |line| line[1], line[2] = line[2], line[1] case line[0] when '-' then line[0] = '+' when '+' then line[0] = '-' end line } end def change_diff(diff) map_diffs(diff, Diff::LCS::Change) end def context_diff(diff) map_diffs(diff, Diff::LCS::ContextChange) end def format_diffs(diffs) diffs.map do |e| if e.kind_of?(Array) e.map { |f| f.to_a.join }.join(", ") else e.to_a.join end end.join("\n") end def map_diffs(diffs, klass = Diff::LCS::ContextChange) diffs.map do |chunks| if klass == Diff::LCS::ContextChange klass.from_a(chunks) else chunks.map { |changes| klass.from_a(changes) } end end end def balanced_traversal(s1, s2, callback_type) callback = __send__(callback_type) Diff::LCS.traverse_balanced(s1, s2, callback) callback end def balanced_reverse(change_result) new_result = [] change_result.each { |line| line = [ line[0], line[2], line[1] ] case line[0] when '<' line[0] = '>' when '>' line[0] = '<' end new_result << line } new_result.sort_by { |line| [ line[1], line[2] ] } end def map_to_no_change(change_result) new_result = [] change_result.each { |line| case line[0] when '!' new_result << [ '<', line[1], line[2] ] new_result << [ '>', line[1] + 1, line[2] ] else new_result << line end } new_result end def simple_callback callbacks = Object.new class << callbacks attr_reader :matched_a attr_reader :matched_b attr_reader :discards_a attr_reader :discards_b attr_reader :done_a attr_reader :done_b def reset @matched_a = [] @matched_b = [] @discards_a = [] @discards_b = [] @done_a = [] @done_b = [] end def match(event) @matched_a << event.old_element @matched_b << event.new_element end def discard_b(event) @discards_b << event.new_element end def discard_a(event) @discards_a << event.old_element end def finished_a(event) @done_a << [event.old_element, event.old_position, event.new_element, event.new_position] end def finished_b(event) p "called #finished_b" @done_b << [event.old_element, event.old_position, event.new_element, event.new_position] end end callbacks.reset callbacks end def simple_callback_no_finishers simple = simple_callback class << simple undef :finished_a undef :finished_b end simple end def balanced_callback cb = Object.new class << cb attr_reader :result def reset @result = [] end def match(event) @result << [ "=", event.old_position, event.new_position ] end def discard_a(event) @result << [ "<", event.old_position, event.new_position ] end def discard_b(event) @result << [ ">", event.old_position, event.new_position ] end def change(event) @result << [ "!", event.old_position, event.new_position ] end end cb.reset cb end def balanced_callback_no_change balanced = balanced_callback class << balanced undef :change end balanced end module Matchers extend RSpec::Matchers::DSL matcher :be_nil_or_match_values do |ii, s1, s2| match do |ee| expect(ee).to(satisfy { |vee| vee.nil? || s1[ii] == s2[ee] }) end end matcher :correctly_map_sequence do |s1| match do |actual| actual.each_with_index { |ee, ii| expect(ee).to be_nil_or_match_values(ii, s1, @s2) } end chain :to_other_sequence do |s2| @s2 = s2 end end end end RSpec.configure do |conf| conf.include Diff::LCS::SpecHelper conf.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:' conf.filter_run_excluding :broken => true end diff-lcs-1.3/spec/patch_spec.rb0000644000004100000410000003542413041652267016502 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe "Diff::LCS.patch" do include Diff::LCS::SpecHelper::Matchers shared_examples "patch sequences correctly" do it "correctly patches left-to-right (patch autodiscovery)" do expect(Diff::LCS.patch(s1, patch_set)).to eq(s2) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(s1, patch_set, :patch)).to eq(s2) expect(Diff::LCS.patch!(s1, patch_set)).to eq(s2) end it "correctly patches right-to-left (unpatch autodiscovery)" do expect(Diff::LCS.patch(s2, patch_set)).to eq(s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(s2, patch_set, :unpatch)).to eq(s1) expect(Diff::LCS.unpatch!(s2, patch_set)).to eq(s1) end end describe "using a Diff::LCS.diff patchset" do describe "an empty patchset returns the source" do it "works on a string (hello)" do diff = Diff::LCS.diff(hello, hello) expect(Diff::LCS::patch(hello, diff)).to eq(hello) end it "works on an array %W(h e l l o)" do diff = Diff::LCS.diff(hello_ary, hello_ary) expect(Diff::LCS::patch(hello_ary, diff)).to eq(hello_ary) end end describe "with default diff callbacks (DiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.diff(seq1, seq2) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.diff(seq2, seq1) } end end end describe "with context diff callbacks (ContextDiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.diff(seq2, seq1, Diff::LCS::ContextDiffCallbacks) } end end end describe "with sdiff callbacks (SDiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.diff(seq1, seq2, Diff::LCS::SDiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.diff(seq2, seq1, Diff::LCS::SDiffCallbacks) } end end end end describe "using a Diff::LCS.sdiff patchset" do describe "an empty patchset returns the source" do it "works on a string (hello)" do expect(Diff::LCS::patch(hello, Diff::LCS.sdiff(hello, hello))).to eq(hello) end it "works on an array %W(h e l l o)" do expect(Diff::LCS::patch(hello_ary, Diff::LCS.sdiff(hello_ary, hello_ary))).to eq(hello_ary) end end describe "with default diff callbacks (DiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.sdiff(seq1, seq2, Diff::LCS::DiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.sdiff(seq2, seq1, Diff::LCS::DiffCallbacks) } end end end describe "with context diff callbacks (DiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.sdiff(seq2, seq1, Diff::LCS::ContextDiffCallbacks) } end end end describe "with sdiff callbacks (SDiffCallbacks)" do describe "forward (s1 -> s2)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq1 } let(:s2) { seq2 } let(:patch_set) { Diff::LCS.sdiff(seq1, seq2) } end end describe "reverse (s2 -> s1)" do it_has_behavior "patch sequences correctly" do let(:s1) { seq2 } let(:s2) { seq1 } let(:patch_set) { Diff::LCS.sdiff(seq2, seq1) } end end end end # Note: because of the error in autodiscovery ("does not autodiscover s1 # to s2 patches"), this cannot use the "patch sequences correctly" shared # set. Once the bug in autodiscovery is fixed, this can be converted as # above. describe "fix bug 891: patchsets do not contain the last equal part" do before :each do @s1 = %w(a b c d e f g h i j k) @s2 = %w(a b c d D e f g h i j k) end describe "using Diff::LCS.diff with default diff callbacks" do before :each do @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2) @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.diff with context diff callbacks" do before :each do @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::ContextDiffCallbacks) @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::ContextDiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.diff with sdiff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.diff(@s1, @s2, Diff::LCS::SDiffCallbacks) @patch_set_s2_s1 = Diff::LCS.diff(@s2, @s1, Diff::LCS::SDiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.sdiff with default sdiff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2) @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.sdiff with context diff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::ContextDiffCallbacks) @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::ContextDiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end describe "using Diff::LCS.sdiff with default diff callbacks" do before(:each) do @patch_set_s1_s2 = Diff::LCS.sdiff(@s1, @s2, Diff::LCS::DiffCallbacks) @patch_set_s2_s1 = Diff::LCS.sdiff(@s2, @s1, Diff::LCS::DiffCallbacks) end it "autodiscovers s1 to s2 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 patches" do expect do expect(Diff::LCS.patch(@s1, @patch_set_s2_s1)).to eq(@s2) end.to_not raise_error end it "autodiscovers s2 to s1 the left-to-right patches" do expect(Diff::LCS.patch(@s2, @patch_set_s2_s1)).to eq(@s1) expect(Diff::LCS.patch(@s2, @patch_set_s1_s2)).to eq(@s1) end it "correctly patches left-to-right (explicit patch)" do expect(Diff::LCS.patch(@s1, @patch_set_s1_s2, :patch)).to eq(@s2) expect(Diff::LCS.patch(@s2, @patch_set_s2_s1, :patch)).to eq(@s1) expect(Diff::LCS.patch!(@s1, @patch_set_s1_s2)).to eq(@s2) expect(Diff::LCS.patch!(@s2, @patch_set_s2_s1)).to eq(@s1) end it "correctly patches right-to-left (explicit unpatch)" do expect(Diff::LCS.patch(@s2, @patch_set_s1_s2, :unpatch)).to eq(@s1) expect(Diff::LCS.patch(@s1, @patch_set_s2_s1, :unpatch)).to eq(@s2) expect(Diff::LCS.unpatch!(@s2, @patch_set_s1_s2)).to eq(@s1) expect(Diff::LCS.unpatch!(@s1, @patch_set_s2_s1)).to eq(@s2) end end end end diff-lcs-1.3/spec/diff_spec.rb0000644000004100000410000000250013041652267016300 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe Diff::LCS, ".diff" do include Diff::LCS::SpecHelper::Matchers it "correctly diffs seq1 to seq2" do diff_s1_s2 = Diff::LCS.diff(seq1, seq2) expect(change_diff(correct_forward_diff)).to eq(diff_s1_s2) end it "correctly diffs seq2 to seq1" do diff_s2_s1 = Diff::LCS.diff(seq2, seq1) expect(change_diff(correct_backward_diff)).to eq(diff_s2_s1) end it "correctly diffs against an empty sequence" do diff = Diff::LCS.diff(word_sequence, []) correct_diff = [ [ [ '-', 0, 'abcd' ], [ '-', 1, 'efgh' ], [ '-', 2, 'ijkl' ], [ '-', 3, 'mnopqrstuvwxyz' ] ] ] expect(change_diff(correct_diff)).to eq(diff) diff = Diff::LCS.diff([], word_sequence) correct_diff.each { |hunk| hunk.each { |change| change[0] = '+' } } expect(change_diff(correct_diff)).to eq(diff) end it "correctly diffs 'xx' and 'xaxb'" do left = 'xx' right = 'xaxb' expect(Diff::LCS.patch(left, Diff::LCS.diff(left, right))).to eq(right) end it "returns an empty diff with (hello, hello)" do expect(Diff::LCS.diff(hello, hello)).to be_empty end it "returns an empty diff with (hello_ary, hello_ary)" do expect(Diff::LCS.diff(hello_ary, hello_ary)).to be_empty end end diff-lcs-1.3/spec/fixtures/0000755000004100000410000000000013041652267015705 5ustar www-datawww-datadiff-lcs-1.3/spec/fixtures/ds1.csv0000644000004100000410000000053413041652267017113 0ustar www-datawww-data1,3 2,7 3,13 4,21 5,31 6,43 7,57 8,73 9,91 10,111 11,133 12,157 13,183 14,211 15,241 16,273 17,307 18,343 19,381 20,421 21,463 22,507 23,553 24,601 25,651 26,703 27,757 28,813 29,871 30,931 31,993 32,1057 33,1123 34,1191 35,1261 36,1333 37,1407 38,1483 39,1561 40,1641 41,1723 42,1807 43,1893 44,1981 45,2071 46,2163 47,2257 48,2353 49,2451 50,2500diff-lcs-1.3/spec/fixtures/ds2.csv0000644000004100000410000000054713041652267017120 0ustar www-datawww-data 1,3 2,7 3,13 4,21 5,31 6,42 7,57 8,73 9,91 10,111 11,133 12,157 13,183 14,211 15,241 16,273 17,307 18,343 19,200 20,421 21,463 22,507 23,553 24,601 25,651 26,703 27,757 28,813 29,871 30,931 31,123 32,1057 33,1123 34,1000 35,1261 36,1333 37,1407 38,1483 39,1561 40,1641 41,1723 42,1807 43,1893 44,1981 45,2071 46,2163 47,1524 48,2353 49,2451 50,2500 51,2520 diff-lcs-1.3/spec/issues_spec.rb0000644000004100000410000000233413041652267016710 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- 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 diff-lcs-1.3/spec/traverse_sequences_spec.rb0000644000004100000410000001127313041652267021305 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe "Diff::LCS.traverse_sequences" do describe "callback with no finishers" do describe "over (seq1, seq2)" do before(:each) do @callback_s1_s2 = simple_callback_no_finishers Diff::LCS.traverse_sequences(seq1, seq2, @callback_s1_s2) @callback_s2_s1 = simple_callback_no_finishers Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1) end it "has the correct LCS result on left-matches" do expect(@callback_s1_s2.matched_a).to eq(correct_lcs) expect(@callback_s2_s1.matched_a).to eq(correct_lcs) end it "has the correct LCS result on right-matches" do expect(@callback_s1_s2.matched_b).to eq(correct_lcs) expect(@callback_s2_s1.matched_b).to eq(correct_lcs) end it "has the correct skipped sequences with the left sequence" do expect(@callback_s1_s2.discards_a).to eq(skipped_seq1) expect(@callback_s2_s1.discards_a).to eq(skipped_seq2) end it "has the correct skipped sequences with the right sequence" do expect(@callback_s1_s2.discards_b).to eq(skipped_seq2) expect(@callback_s2_s1.discards_b).to eq(skipped_seq1) end it "does not have anything done markers from the left or right sequences" do expect(@callback_s1_s2.done_a).to be_empty expect(@callback_s1_s2.done_b).to be_empty expect(@callback_s2_s1.done_a).to be_empty expect(@callback_s2_s1.done_b).to be_empty end end describe "over (hello, hello)" do before(:each) do @callback = simple_callback_no_finishers Diff::LCS.traverse_sequences(hello, hello, @callback) end it "has the correct LCS result on left-matches" do expect(@callback.matched_a).to eq(hello.split(//)) end it "has the correct LCS result on right-matches" do expect(@callback.matched_b).to eq(hello.split(//)) end it "has the correct skipped sequences with the left sequence", :only => true do expect(@callback.discards_a).to be_empty end it "has the correct skipped sequences with the right sequence" do expect(@callback.discards_b).to be_empty end it "does not have anything done markers from the left or right sequences" do expect(@callback.done_a).to be_empty expect(@callback.done_b).to be_empty end end describe "over (hello_ary, hello_ary)" do before(:each) do @callback = simple_callback_no_finishers Diff::LCS.traverse_sequences(hello_ary, hello_ary, @callback) end it "has the correct LCS result on left-matches" do expect(@callback.matched_a).to eq(hello_ary) end it "has the correct LCS result on right-matches" do expect(@callback.matched_b).to eq(hello_ary) end it "has the correct skipped sequences with the left sequence" do expect(@callback.discards_a).to be_empty end it "has the correct skipped sequences with the right sequence" do expect(@callback.discards_b).to be_empty end it "does not have anything done markers from the left or right sequences" do expect(@callback.done_a).to be_empty expect(@callback.done_b).to be_empty end end end describe "callback with finisher" do before(:each) do @callback_s1_s2 = simple_callback Diff::LCS.traverse_sequences(seq1, seq2, @callback_s1_s2) @callback_s2_s1 = simple_callback Diff::LCS.traverse_sequences(seq2, seq1, @callback_s2_s1) end it "has the correct LCS result on left-matches" do expect(@callback_s1_s2.matched_a).to eq(correct_lcs) expect(@callback_s2_s1.matched_a).to eq(correct_lcs) end it "has the correct LCS result on right-matches" do expect(@callback_s1_s2.matched_b).to eq(correct_lcs) expect(@callback_s2_s1.matched_b).to eq(correct_lcs) end it "has the correct skipped sequences for the left sequence" do expect(@callback_s1_s2.discards_a).to eq(skipped_seq1) expect(@callback_s2_s1.discards_a).to eq(skipped_seq2) end it "has the correct skipped sequences for the right sequence" do expect(@callback_s1_s2.discards_b).to eq(skipped_seq2) expect(@callback_s2_s1.discards_b).to eq(skipped_seq1) end it "has done markers differently-sized sequences" do expect(@callback_s1_s2.done_a).to eq([[ "p", 9, "s", 10 ]]) expect(@callback_s1_s2.done_b).to be_empty # 20110731 I don't yet understand why this particular behaviour # isn't transitive. expect(@callback_s2_s1.done_a).to be_empty expect(@callback_s2_s1.done_b).to be_empty end end end diff-lcs-1.3/spec/lcs_spec.rb0000644000004100000410000000330513041652267016155 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'spec_helper' describe Diff::LCS::Internals, ".lcs" do include Diff::LCS::SpecHelper::Matchers it "returns a meaningful LCS array with (seq1, seq2)" do res = Diff::LCS::Internals.lcs(seq1, seq2) # The result of the LCS (less the +nil+ values) must be as long as the # correct result. expect(res.compact.size).to eq(correct_lcs.size) expect(res).to correctly_map_sequence(seq1).to_other_sequence(seq2) # Compact these transformations and they should be the correct LCS. x_seq1 = (0...res.size).map { |ix| res[ix] ? seq1[ix] : nil }.compact x_seq2 = (0...res.size).map { |ix| res[ix] ? seq2[res[ix]] : nil }.compact expect(x_seq1).to eq(correct_lcs) expect(x_seq2).to eq(correct_lcs) end it "returns all indexes with (hello, hello)" do expect(Diff::LCS::Internals.lcs(hello, hello)).to \ eq((0...hello.size).to_a) end it "returns all indexes with (hello_ary, hello_ary)" do expect(Diff::LCS::Internals.lcs(hello_ary, hello_ary)).to \ eq((0...hello_ary.size).to_a) end end describe Diff::LCS, ".LCS" do include Diff::LCS::SpecHelper::Matchers it "returns the correct compacted values from Diff::LCS.LCS" do res = Diff::LCS.LCS(seq1, seq2) expect(res).to eq(correct_lcs) expect(res.compact).to eq(res) end it "is transitive" do res = Diff::LCS.LCS(seq2, seq1) expect(res).to eq(correct_lcs) expect(res.compact).to eq(res) end it "returns %W(h e l l o) with (hello, hello)" do expect(Diff::LCS.LCS(hello, hello)).to eq(hello.split(//)) end it "returns hello_ary with (hello_ary, hello_ary)" do expect(Diff::LCS.LCS(hello_ary, hello_ary)).to eq(hello_ary) end end diff-lcs-1.3/README.rdoc0000644000004100000410000000663613041652267014723 0ustar www-datawww-data= Diff::LCS home :: https://github.com/halostatue/diff-lcs code :: https://github.com/halostatue/diff-lcs bugs :: https://github.com/halostatue/diff-lcs/issues rdoc :: http://rubydoc.info/github/halostatue/diff-lcs continuous integration :: {}[https://travis-ci.org/halostatue/diff-lcs] test coverage :: {Coverage Status}[https://coveralls.io/r/halostatue/diff-lcs] == Description Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities to create a simple HTML diff output format and a standard diff-like tool. This is release 1.3, providing a tentative fix to a long-standing issue related to incorrect detection of a patch direction. Also modernizes the gem infrastructure, testing infrastructure, and provides a warning-free experience to Ruby 2.4 users. == Synopsis Using this module is quite simple. By default, Diff::LCS does not extend objects with the Diff::LCS interface, but will be called as if it were a function: require 'diff/lcs' seq1 = %w(a b c e h j l m n p) seq2 = %w(b c d e f j k l m r s t) lcs = Diff::LCS.LCS(seq1, seq2) diffs = Diff::LCS.diff(seq1, seq2) sdiff = Diff::LCS.sdiff(seq1, seq2) seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj) bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj) seq2 == Diff::LCS.patch!(seq1, diffs) seq1 == Diff::LCS.unpatch!(seq2, diffs) seq2 == Diff::LCS.patch!(seq1, sdiff) seq1 == Diff::LCS.unpatch!(seq2, sdiff) Objects can be extended with Diff::LCS: seq1.extend(Diff::LCS) lcs = seq1.lcs(seq2) diffs = seq1.diff(seq2) sdiff = seq1.sdiff(seq2) seq = seq1.traverse_sequences(seq2, callback_obj) bal = seq1.traverse_balanced(seq2, callback_obj) seq2 == seq1.patch!(diffs) seq1 == seq2.unpatch!(diffs) seq2 == seq1.patch!(sdiff) seq1 == seq2.unpatch!(sdiff) By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be extended for use this way. Note that Diff::LCS requires a sequenced enumerable container, which means that the order of enumeration is both predictable and consistent for the same set of data. While it is theoretically possible to generate a diff for an unordered hash, it will only be meaningful if the enumeration of the hashes is consistent. In general, this will mean that containers that behave like String or Array will perform best. == History Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt longest common subsequence (LCS) algorithm to compute intelligent differences between two sequenced enumerable containers. The implementation is based on Mario I. Wolczko's {Smalltalk version 1.2}[ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st] (1993) and Ned Konz's Perl version {Algorithm::Diff 1.15}[http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/]. Diff::LCS#sdiff and Diff::LCS#traverse_balanced were originally written for the Perl version by Mike Schilli. The algorithm is described in A Fast Algorithm for Computing Longest Common Subsequences, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor improvements to improve the speed. A simplified description of the algorithm, originally written for the Perl version, was written by Mark-Jason Dominus. :include: Contributing.rdoc :include: License.rdoc diff-lcs-1.3/lib/0000755000004100000410000000000013041652267013650 5ustar www-datawww-datadiff-lcs-1.3/lib/diff/0000755000004100000410000000000013041652267014560 5ustar www-datawww-datadiff-lcs-1.3/lib/diff/lcs/0000755000004100000410000000000013041652267015341 5ustar www-datawww-datadiff-lcs-1.3/lib/diff/lcs/string.rb0000644000004100000410000000010513041652267017170 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- class String include Diff::LCS end diff-lcs-1.3/lib/diff/lcs/ldiff.rb0000644000004100000410000001150713041652267016756 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'optparse' require 'ostruct' require 'diff/lcs/hunk' module Diff::LCS::Ldiff #:nodoc: BANNER = <<-COPYRIGHT ldiff #{Diff::LCS::VERSION} Copyright 2004-2014 Austin Ziegler Part of Diff::LCS. https://github.com/halostatue/diff-lcs This program is free software. It may be redistributed and/or modified under the terms of the GPL version 2 (or later), the Perl Artistic licence, or the MIT licence. COPYRIGHT end class << Diff::LCS::Ldiff attr_reader :format, :lines #:nodoc: attr_reader :file_old, :file_new #:nodoc: attr_reader :data_old, :data_new #:nodoc: def run(args, input = $stdin, output = $stdout, error = $stderr) #:nodoc: @binary = nil args.options do |o| o.banner = "Usage: #{File.basename($0)} [options] oldfile newfile" o.separator "" o.on('-c', '-C', '--context [LINES]', Numeric, 'Displays a context diff with LINES lines', 'of context. Default 3 lines.') do |ctx| @format = :context @lines = ctx || 3 end o.on('-u', '-U', '--unified [LINES]', Numeric, 'Displays a unified diff with LINES lines', 'of context. Default 3 lines.') do |ctx| @format = :unified @lines = ctx || 3 end o.on('-e', 'Creates an \'ed\' script to change', 'oldfile to newfile.') do |ctx| @format = :ed end o.on('-f', 'Creates an \'ed\' script to change', 'oldfile to newfile in reverse order.') do |ctx| @format = :reverse_ed end o.on('-a', '--text', 'Treat the files as text and compare them', 'line-by-line, even if they do not seem', 'to be text.') do |txt| @binary = false end o.on('--binary', 'Treats the files as binary.') do |bin| @binary = true end o.on('-q', '--brief', 'Report only whether or not the files', 'differ, not the details.') do |ctx| @format = :report end o.on_tail('--help', 'Shows this text.') do error << o return 0 end o.on_tail('--version', 'Shows the version of Diff::LCS.') do error << Diff::LCS::Ldiff::BANNER return 0 end o.on_tail "" o.on_tail 'By default, runs produces an "old-style" diff, with output like UNIX diff.' o.parse! end unless args.size == 2 error << args.options return 127 end # Defaults are for old-style diff @format ||= :old @lines ||= 0 file_old, file_new = *ARGV case @format when :context char_old = '*' * 3 char_new = '-' * 3 when :unified char_old = '-' * 3 char_new = '+' * 3 end # After we've read up to a certain point in each file, the number of # items we've read from each file will differ by FLD (could be 0). file_length_difference = 0 if @binary.nil? or @binary data_old = IO.read(file_old) data_new = IO.read(file_new) # Test binary status if @binary.nil? old_txt = data_old[0, 4096].scan(/\0/).empty? new_txt = data_new[0, 4096].scan(/\0/).empty? @binary = (not old_txt) or (not new_txt) old_txt = new_txt = nil end unless @binary data_old = data_old.split($/).map { |e| e.chomp } data_new = data_new.split($/).map { |e| e.chomp } end else data_old = IO.readlines(file_old).map { |e| e.chomp } data_new = IO.readlines(file_new).map { |e| e.chomp } end # diff yields lots of pieces, each of which is basically a Block object if @binary diffs = (data_old == data_new) else diffs = Diff::LCS.diff(data_old, data_new) diffs = nil if diffs.empty? end return 0 unless diffs if @format == :report output << "Files #{file_old} and #{file_new} differ\n" return 1 end if (@format == :unified) or (@format == :context) ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z') output << "#{char_old} #{file_old}\t#{ft}\n" ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z') output << "#{char_new} #{file_new}\t#{ft}\n" end # Loop over hunks. If a hunk overlaps with the last hunk, join them. # Otherwise, print out the old one. oldhunk = hunk = nil if @format == :ed real_output = output output = [] end diffs.each do |piece| begin hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines, file_length_difference) file_length_difference = hunk.file_length_difference next unless oldhunk next if (@lines > 0) and hunk.merge(oldhunk) output << oldhunk.diff(@format) << "\n" ensure oldhunk = hunk end end output << oldhunk.diff(@format) << "\n" if @format == :ed output.reverse_each { |e| real_output << e.diff(:ed_finish) } end return 1 end end diff-lcs-1.3/lib/diff/lcs/change.rb0000644000004100000410000001033013041652267017110 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- # Represents a simplistic (non-contextual) change. Represents the removal or # addition of an element from either the old or the new sequenced # enumerable. class Diff::LCS::Change IntClass = 1.class # Fixnum is deprecated in Ruby 2.4 # The only actions valid for changes are '+' (add), '-' (delete), '=' # (no change), '!' (changed), '<' (tail changes from first sequence), or # '>' (tail changes from second sequence). The last two ('<>') are only # found with Diff::LCS::diff and Diff::LCS::sdiff. VALID_ACTIONS = %W(+ - = ! > <) def self.valid_action?(action) VALID_ACTIONS.include? action end # Returns the action this Change represents. attr_reader :action # Returns the position of the Change. attr_reader :position # Returns the sequence element of the Change. attr_reader :element def initialize(*args) @action, @position, @element = *args unless Diff::LCS::Change.valid_action?(@action) raise "Invalid Change Action '#{@action}'" end raise "Invalid Position Type" unless @position.kind_of? IntClass end def inspect to_a.inspect end def to_a [ @action, @position, @element ] end def self.from_a(arr) arr = arr.flatten(1) case arr.size when 5 Diff::LCS::ContextChange.new(*(arr[0...5])) when 3 Diff::LCS::Change.new(*(arr[0...3])) else raise "Invalid change array format provided." end end include Comparable def ==(other) (self.class == other.class) and (self.action == other.action) and (self.position == other.position) and (self.element == other.element) end def <=>(other) r = self.action <=> other.action r = self.position <=> other.position if r.zero? r = self.element <=> other.element if r.zero? r end def adding? @action == '+' end def deleting? @action == '-' end def unchanged? @action == '=' end def changed? @action == '!' end def finished_a? @action == '>' end def finished_b? @action == '<' end end # Represents a contextual change. Contains the position and values of the # elements in the old and the new sequenced enumerables as well as the action # taken. class Diff::LCS::ContextChange < Diff::LCS::Change # We don't need these two values. undef :position undef :element # Returns the old position being changed. attr_reader :old_position # Returns the new position being changed. attr_reader :new_position # Returns the old element being changed. attr_reader :old_element # Returns the new element being changed. attr_reader :new_element def initialize(*args) @action, @old_position, @old_element, @new_position, @new_element = *args unless Diff::LCS::Change.valid_action?(@action) raise "Invalid Change Action '#{@action}'" end unless @old_position.nil? or @old_position.kind_of? IntClass raise "Invalid (Old) Position Type" end unless @new_position.nil? or @new_position.kind_of? IntClass raise "Invalid (New) Position Type" end end def to_a [ @action, [ @old_position, @old_element ], [ @new_position, @new_element ] ] end def inspect(*args) to_a.inspect end def self.from_a(arr) Diff::LCS::Change.from_a(arr) end # Simplifies a context change for use in some diff callbacks. '<' actions # are converted to '-' and '>' actions are converted to '+'. def self.simplify(event) ea = event.to_a case ea[0] when '-' ea[2][1] = nil when '<' ea[0] = '-' ea[2][1] = nil when '+' ea[1][1] = nil when '>' ea[0] = '+' ea[1][1] = nil end Diff::LCS::ContextChange.from_a(ea) end def ==(other) (self.class == other.class) and (@action == other.action) and (@old_position == other.old_position) and (@new_position == other.new_position) and (@old_element == other.old_element) and (@new_element == other.new_element) end def <=>(other) r = @action <=> other.action r = @old_position <=> other.old_position if r.zero? r = @new_position <=> other.new_position if r.zero? r = @old_element <=> other.old_element if r.zero? r = @new_element <=> other.new_element if r.zero? r end end diff-lcs-1.3/lib/diff/lcs/internals.rb0000644000004100000410000002044513041652267017672 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- class << Diff::LCS def diff_traversal(method, seq1, seq2, callbacks, &block) callbacks = callbacks_for(callbacks) case method when :diff traverse_sequences(seq1, seq2, callbacks) when :sdiff traverse_balanced(seq1, seq2, callbacks) end callbacks.finish if callbacks.respond_to? :finish if block callbacks.diffs.map do |hunk| if hunk.kind_of? Array hunk.map { |hunk_block| block[hunk_block] } else block[hunk] end end else callbacks.diffs end end private :diff_traversal end module Diff::LCS::Internals # :nodoc: end class << Diff::LCS::Internals # Compute the longest common subsequence between the sequenced # Enumerables +a+ and +b+. The result is an array whose contents is such # that # # result = Diff::LCS::Internals.lcs(a, b) # result.each_with_index do |e, i| # assert_equal(a[i], b[e]) unless e.nil? # end def lcs(a, b) a_start = b_start = 0 a_finish = a.size - 1 b_finish = b.size - 1 vector = [] # Prune off any common elements at the beginning... while ((a_start <= a_finish) and (b_start <= b_finish) and (a[a_start] == b[b_start])) vector[a_start] = b_start a_start += 1 b_start += 1 end b_start = a_start # Now the end... while ((a_start <= a_finish) and (b_start <= b_finish) and (a[a_finish] == b[b_finish])) vector[a_finish] = b_finish a_finish -= 1 b_finish -= 1 end # Now, compute the equivalence classes of positions of elements. b_matches = position_hash(b, b_start..b_finish) thresh = [] links = [] string = a.kind_of?(String) (a_start .. a_finish).each do |i| ai = string ? a[i, 1] : a[i] bm = b_matches[ai] k = nil bm.reverse_each do |j| if k and (thresh[k] > j) and (thresh[k - 1] < j) thresh[k] = j else k = replace_next_larger(thresh, j, k) end links[k] = [ (k > 0) ? links[k - 1] : nil, i, j ] unless k.nil? end end unless thresh.empty? link = links[thresh.size - 1] while not link.nil? vector[link[1]] = link[2] link = link[0] end end vector end # This method will analyze the provided patchset to provide a # single-pass normalization (conversion of the array form of # Diff::LCS::Change objects to the object form of same) and detection of # whether the patchset represents changes to be made. def analyze_patchset(patchset, depth = 0) raise "Patchset too complex" if depth > 1 has_changes = false # Format: # [ # patchset # # hunk (change) # [ # hunk # # change # ] # ] patchset = patchset.map do |hunk| case hunk when Diff::LCS::Change has_changes ||= !hunk.unchanged? hunk when Array # Detect if the 'hunk' is actually an array-format # Change object. if Diff::LCS::Change.valid_action? hunk[0] hunk = Diff::LCS::Change.from_a(hunk) has_changes ||= !hunk.unchanged? hunk else with_changes, hunk = analyze_patchset(hunk, depth + 1) has_changes ||= with_changes hunk.flatten end else raise ArgumentError, "Cannot normalise a hunk of class #{hunk.class}." end end [ has_changes, patchset.flatten(1) ] end # Examine the patchset and the source to see in which direction the # patch should be applied. # # WARNING: By default, this examines the whole patch, so this could take # some time. This also works better with Diff::LCS::ContextChange or # Diff::LCS::Change as its source, as an array will cause the creation # of one of the above. def intuit_diff_direction(src, patchset, limit = nil) string = src.kind_of?(String) count = left_match = left_miss = right_match = right_miss = 0 patchset.each do |change| count += 1 case change when Diff::LCS::ContextChange le = string ? src[change.old_position, 1] : src[change.old_position] re = string ? src[change.new_position, 1] : src[change.new_position] case change.action when '-' # Remove details from the old string if le == change.old_element left_match += 1 else left_miss += 1 end when '+' if re == change.new_element right_match += 1 else right_miss += 1 end when '=' left_miss += 1 if le != change.old_element right_miss += 1 if re != change.new_element when '!' if le == change.old_element left_match += 1 else if re == change.new_element right_match += 1 else left_miss += 1 right_miss += 1 end end end when Diff::LCS::Change # With a simplistic change, we can't tell the difference between # the left and right on '!' actions, so we ignore those. On '=' # actions, if there's a miss, we miss both left and right. element = string ? src[change.position, 1] : src[change.position] case change.action when '-' if element == change.element left_match += 1 else left_miss += 1 end when '+' if element == change.element right_match += 1 else right_miss += 1 end when '=' if element != change.element left_miss += 1 right_miss += 1 end end end break if (not limit.nil?) && (count > limit) end no_left = (left_match == 0) && (left_miss > 0) no_right = (right_match == 0) && (right_miss > 0) case [ no_left, no_right ] when [ false, true ] :patch when [ true, false ] :unpatch else case left_match <=> right_match when 1 if left_miss.zero? :patch else :unpatch end when -1 if right_miss.zero? :unpatch else :patch end else raise "The provided patchset does not appear to apply to the provided enumerable as either source or destination value." end end end # Find the place at which +value+ would normally be inserted into the # Enumerable. If that place is already occupied by +value+, do nothing # and return +nil+. If the place does not exist (i.e., it is off the end # of the Enumerable), add it to the end. Otherwise, replace the element # at that point with +value+. It is assumed that the Enumerable's values # are numeric. # # This operation preserves the sort order. def replace_next_larger(enum, value, last_index = nil) # Off the end? if enum.empty? or (value > enum[-1]) enum << value return enum.size - 1 end # Binary search for the insertion point last_index ||= enum.size first_index = 0 while (first_index <= last_index) i = (first_index + last_index) >> 1 found = enum[i] if value == found return nil elsif value > found first_index = i + 1 else last_index = i - 1 end end # The insertion point is in first_index; overwrite the next larger # value. enum[first_index] = value return first_index end private :replace_next_larger # If +vector+ maps the matching elements of another collection onto this # Enumerable, compute the inverse of +vector+ that maps this Enumerable # onto the collection. (Currently unused.) def inverse_vector(a, vector) inverse = a.dup (0...vector.size).each do |i| inverse[vector[i]] = i unless vector[i].nil? end inverse end private :inverse_vector # Returns a hash mapping each element of an Enumerable to the set of # positions it occupies in the Enumerable, optionally restricted to the # elements specified in the range of indexes specified by +interval+. def position_hash(enum, interval) string = enum.kind_of?(String) hash = Hash.new { |h, k| h[k] = [] } interval.each do |i| k = string ? enum[i, 1] : enum[i] hash[k] << i end hash end private :position_hash end diff-lcs-1.3/lib/diff/lcs/block.rb0000644000004100000410000000137213041652267016763 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- # A block is an operation removing, adding, or changing a group of items. # Basically, this is just a list of changes, where each change adds or # deletes a single item. Used by bin/ldiff. class Diff::LCS::Block attr_reader :changes, :insert, :remove def initialize(chunk) @changes = [] @insert = [] @remove = [] chunk.each do |item| @changes << item @remove << item if item.deleting? @insert << item if item.adding? end end def diff_size @insert.size - @remove.size end def op case [@remove.empty?, @insert.empty?] when [false, false] '!' when [false, true] '-' when [true, false] '+' else # [true, true] '^' end end end diff-lcs-1.3/lib/diff/lcs/array.rb0000644000004100000410000000013013041652267016776 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'diff/lcs' class Array include Diff::LCS end diff-lcs-1.3/lib/diff/lcs/callbacks.rb0000644000004100000410000002446713041652267017622 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'diff/lcs/change' module Diff::LCS # This callback object implements the default set of callback events, # which only returns the event itself. Note that #finished_a and # #finished_b are not implemented -- I haven't yet figured out where they # would be useful. # # Note that this is intended to be called as is, e.g., # # Diff::LCS.LCS(seq1, seq2, Diff::LCS::DefaultCallbacks) class DefaultCallbacks class << self # Called when two items match. def match(event) event end # Called when the old value is discarded in favour of the new value. def discard_a(event) event end # Called when the new value is discarded in favour of the old value. def discard_b(event) event end # Called when both the old and new values have changed. def change(event) event end private :new end end # An alias for DefaultCallbacks that is used in # Diff::LCS#traverse_sequences. # # Diff::LCS.LCS(seq1, seq2, Diff::LCS::SequenceCallbacks) SequenceCallbacks = DefaultCallbacks # An alias for DefaultCallbacks that is used in # Diff::LCS#traverse_balanced. # # Diff::LCS.LCS(seq1, seq2, Diff::LCS::BalancedCallbacks) BalancedCallbacks = DefaultCallbacks def self.callbacks_for(callbacks) callbacks.new rescue callbacks end end # This will produce a compound array of simple diff change objects. Each # element in the #diffs array is a +hunk+ or +hunk+ array, where each # element in each +hunk+ array is a single Change object representing the # addition or removal of a single element from one of the two tested # sequences. The +hunk+ provides the full context for the changes. # # diffs = Diff::LCS.diff(seq1, seq2) # # This example shows a simplified array format. # # [ [ [ '-', 0, 'a' ] ], # 1 # # [ [ '+', 2, 'd' ] ], # 2 # # [ [ '-', 4, 'h' ], # 3 # # [ '+', 4, 'f' ] ], # # [ [ '+', 6, 'k' ] ], # 4 # # [ [ '-', 8, 'n' ], # 5 # # [ '-', 9, 'p' ], # # [ '+', 9, 'r' ], # # [ '+', 10, 's' ], # # [ '+', 11, 't' ] ] ] # # There are five hunks here. The first hunk says that the +a+ at position 0 # of the first sequence should be deleted ('-'). The second hunk # says that the +d+ at position 2 of the second sequence should be inserted # ('+'). The third hunk says that the +h+ at position 4 of the # first sequence should be removed and replaced with the +f+ from position 4 # of the second sequence. The other two hunks are described similarly. # # === Use # # This callback object must be initialised and is used by the Diff::LCS#diff # method. # # cbo = Diff::LCS::DiffCallbacks.new # Diff::LCS.LCS(seq1, seq2, cbo) # cbo.finish # # Note that the call to #finish is absolutely necessary, or the last set of # changes will not be visible. Alternatively, can be used as: # # cbo = Diff::LCS::DiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) } # # The necessary #finish call will be made. # # === Simplified Array Format # # The simplified array format used in the example above can be obtained # with: # # require 'pp' # pp diffs.map { |e| e.map { |f| f.to_a } } class Diff::LCS::DiffCallbacks # Returns the difference set collected during the diff process. attr_reader :diffs def initialize # :yields self: @hunk = [] @diffs = [] if block_given? begin yield self ensure self.finish end end end # Finalizes the diff process. If an unprocessed hunk still exists, then it # is appended to the diff list. def finish finish_hunk end def match(event) finish_hunk end def discard_a(event) @hunk << Diff::LCS::Change.new('-', event.old_position, event.old_element) end def discard_b(event) @hunk << Diff::LCS::Change.new('+', event.new_position, event.new_element) end def finish_hunk @diffs << @hunk unless @hunk.empty? @hunk = [] end private :finish_hunk end # This will produce a compound array of contextual diff change objects. Each # element in the #diffs array is a "hunk" array, where each element in each # "hunk" array is a single change. Each change is a Diff::LCS::ContextChange # that contains both the old index and new index values for the change. The # "hunk" provides the full context for the changes. Both old and new objects # will be presented for changed objects. +nil+ will be substituted for a # discarded object. # # seq1 = %w(a b c e h j l m n p) # seq2 = %w(b c d e f j k l m r s t) # # diffs = Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks) # # This example shows a simplified array format. # # [ [ [ '-', [ 0, 'a' ], [ 0, nil ] ] ], # 1 # # [ [ '+', [ 3, nil ], [ 2, 'd' ] ] ], # 2 # # [ [ '-', [ 4, 'h' ], [ 4, nil ] ], # 3 # # [ '+', [ 5, nil ], [ 4, 'f' ] ] ], # # [ [ '+', [ 6, nil ], [ 6, 'k' ] ] ], # 4 # # [ [ '-', [ 8, 'n' ], [ 9, nil ] ], # 5 # # [ '+', [ 9, nil ], [ 9, 'r' ] ], # # [ '-', [ 9, 'p' ], [ 10, nil ] ], # # [ '+', [ 10, nil ], [ 10, 's' ] ], # # [ '+', [ 10, nil ], [ 11, 't' ] ] ] ] # # The five hunks shown are comprised of individual changes; if there is a # related set of changes, they are still shown individually. # # This callback can also be used with Diff::LCS#sdiff, which will produce # results like: # # diffs = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextCallbacks) # # This example shows a simplified array format. # # [ [ [ "-", [ 0, "a" ], [ 0, nil ] ] ], # 1 # # [ [ "+", [ 3, nil ], [ 2, "d" ] ] ], # 2 # # [ [ "!", [ 4, "h" ], [ 4, "f" ] ] ], # 3 # # [ [ "+", [ 6, nil ], [ 6, "k" ] ] ], # 4 # # [ [ "!", [ 8, "n" ], [ 9, "r" ] ], # 5 # # [ "!", [ 9, "p" ], [ 10, "s" ] ], # # [ "+", [ 10, nil ], [ 11, "t" ] ] ] ] # # The five hunks are still present, but are significantly shorter in total # presentation, because changed items are shown as changes ("!") instead of # potentially "mismatched" pairs of additions and deletions. # # The result of this operation is similar to that of # Diff::LCS::SDiffCallbacks. They may be compared as: # # s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" } # c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten # # s == c # -> true # # === Use # # This callback object must be initialised and can be used by the # Diff::LCS#diff or Diff::LCS#sdiff methods. # # cbo = Diff::LCS::ContextDiffCallbacks.new # Diff::LCS.LCS(seq1, seq2, cbo) # cbo.finish # # Note that the call to #finish is absolutely necessary, or the last set of # changes will not be visible. Alternatively, can be used as: # # cbo = Diff::LCS::ContextDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) } # # The necessary #finish call will be made. # # === Simplified Array Format # # The simplified array format used in the example above can be obtained # with: # # require 'pp' # pp diffs.map { |e| e.map { |f| f.to_a } } class Diff::LCS::ContextDiffCallbacks < Diff::LCS::DiffCallbacks def discard_a(event) @hunk << Diff::LCS::ContextChange.simplify(event) end def discard_b(event) @hunk << Diff::LCS::ContextChange.simplify(event) end def change(event) @hunk << Diff::LCS::ContextChange.simplify(event) end end # This will produce a simple array of diff change objects. Each element in # the #diffs array is a single ContextChange. In the set of #diffs provided # by SDiffCallbacks, both old and new objects will be presented for both # changed and unchanged objects. +nil+ will be substituted # for a discarded object. # # The diffset produced by this callback, when provided to Diff::LCS#sdiff, # will compute and display the necessary components to show two sequences # and their minimized differences side by side, just like the Unix utility # +sdiff+. # # same same # before | after # old < - # - > new # # seq1 = %w(a b c e h j l m n p) # seq2 = %w(b c d e f j k l m r s t) # # diffs = Diff::LCS.sdiff(seq1, seq2) # # This example shows a simplified array format. # # [ [ "-", [ 0, "a"], [ 0, nil ] ], # # [ "=", [ 1, "b"], [ 0, "b" ] ], # # [ "=", [ 2, "c"], [ 1, "c" ] ], # # [ "+", [ 3, nil], [ 2, "d" ] ], # # [ "=", [ 3, "e"], [ 3, "e" ] ], # # [ "!", [ 4, "h"], [ 4, "f" ] ], # # [ "=", [ 5, "j"], [ 5, "j" ] ], # # [ "+", [ 6, nil], [ 6, "k" ] ], # # [ "=", [ 6, "l"], [ 7, "l" ] ], # # [ "=", [ 7, "m"], [ 8, "m" ] ], # # [ "!", [ 8, "n"], [ 9, "r" ] ], # # [ "!", [ 9, "p"], [ 10, "s" ] ], # # [ "+", [ 10, nil], [ 11, "t" ] ] ] # # The result of this operation is similar to that of # Diff::LCS::ContextDiffCallbacks. They may be compared as: # # s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" } # c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten # # s == c # -> true # # === Use # # This callback object must be initialised and is used by the Diff::LCS#sdiff # method. # # cbo = Diff::LCS::SDiffCallbacks.new # Diff::LCS.LCS(seq1, seq2, cbo) # # As with the other initialisable callback objects, # Diff::LCS::SDiffCallbacks can be initialised with a block. As there is no # "fininishing" to be done, this has no effect on the state of the object. # # cbo = Diff::LCS::SDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) } # # === Simplified Array Format # # The simplified array format used in the example above can be obtained # with: # # require 'pp' # pp diffs.map { |e| e.to_a } class Diff::LCS::SDiffCallbacks # Returns the difference set collected during the diff process. attr_reader :diffs def initialize #:yields self: @diffs = [] yield self if block_given? end def match(event) @diffs << Diff::LCS::ContextChange.simplify(event) end def discard_a(event) @diffs << Diff::LCS::ContextChange.simplify(event) end def discard_b(event) @diffs << Diff::LCS::ContextChange.simplify(event) end def change(event) @diffs << Diff::LCS::ContextChange.simplify(event) end end diff-lcs-1.3/lib/diff/lcs/hunk.rb0000644000004100000410000002061613041652267016640 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'diff/lcs/block' # A Hunk is a group of Blocks which overlap because of the context # surrounding each block. (So if we're not using context, every hunk will # contain one block.) Used in the diff program (bin/diff). class Diff::LCS::Hunk # Create a hunk using references to both the old and new data, as well as # the piece of data. def initialize(data_old, data_new, piece, flag_context, file_length_difference) # At first, a hunk will have just one Block in it @blocks = [ Diff::LCS::Block.new(piece) ] if String.method_defined?(:encoding) @preferred_data_encoding = data_old.fetch(0, data_new.fetch(0,'') ).encoding end @data_old = data_old @data_new = data_new before = after = file_length_difference after += @blocks[0].diff_size @file_length_difference = after # The caller must get this manually # Save the start & end of each array. If the array doesn't exist (e.g., # we're only adding items in this block), then figure out the line # number based on the line number of the other file and the current # difference in file lengths. if @blocks[0].remove.empty? a1 = a2 = nil else a1 = @blocks[0].remove[0].position a2 = @blocks[0].remove[-1].position end if @blocks[0].insert.empty? b1 = b2 = nil else b1 = @blocks[0].insert[0].position b2 = @blocks[0].insert[-1].position end @start_old = a1 || (b1 - before) @start_new = b1 || (a1 + before) @end_old = a2 || (b2 - after) @end_new = b2 || (a2 + after) self.flag_context = flag_context end attr_reader :blocks attr_reader :start_old, :start_new attr_reader :end_old, :end_new attr_reader :file_length_difference # Change the "start" and "end" fields to note that context should be added # to this hunk. attr_accessor :flag_context undef :flag_context=; def flag_context=(context) #:nodoc: return if context.nil? or context.zero? add_start = (context > @start_old) ? @start_old : context @start_old -= add_start @start_new -= add_start if (@end_old + context) > @data_old.size add_end = @data_old.size - @end_old else add_end = context end @end_old += add_end @end_new += add_end end # Merges this hunk and the provided hunk together if they overlap. Returns # a truthy value so that if there is no overlap, you can know the merge # was skipped. def merge(hunk) if overlaps?(hunk) @start_old = hunk.start_old @start_new = hunk.start_new blocks.unshift(*hunk.blocks) else nil end end alias_method :unshift, :merge # Determines whether there is an overlap between this hunk and the # provided hunk. This will be true if the difference between the two hunks # start or end positions is within one position of each other. def overlaps?(hunk) hunk and (((@start_old - hunk.end_old) <= 1) or ((@start_new - hunk.end_new) <= 1)) end # Returns a diff string based on a format. def diff(format) case format when :old old_diff when :unified unified_diff when :context context_diff when :ed self when :reverse_ed, :ed_finish ed_diff(format) else raise "Unknown diff format #{format}." end end # Note that an old diff can't have any context. Therefore, we know that # there's only one block in the hunk. def old_diff warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 op_act = { "+" => 'a', "-" => 'd', "!" => "c" } block = @blocks[0] # Calculate item number range. Old diff range is just like a context # diff range, except the ranges are on one line with the action between # them. s = encode("#{context_range(:old)}#{op_act[block.op]}#{context_range(:new)}\n") # If removing anything, just print out all the remove lines in the hunk # which is just all the remove lines in the block. @data_old[@start_old .. @end_old].each { |e| s << encode("< ") + e + encode("\n") } unless block.remove.empty? s << encode("---\n") if block.op == "!" @data_new[@start_new .. @end_new].each { |e| s << encode("> ") + e + encode("\n") } unless block.insert.empty? s end private :old_diff def unified_diff # Calculate item number range. s = encode("@@ -#{unified_range(:old)} +#{unified_range(:new)} @@\n") # Outlist starts containing the hunk of the old file. Removing an item # just means putting a '-' in front of it. Inserting an item requires # getting it from the new file and splicing it in. We splice in # +num_added+ items. Remove blocks use +num_added+ because splicing # changed the length of outlist. # # We remove +num_removed+ items. Insert blocks use +num_removed+ # because their item numbers -- corresponding to positions in the NEW # file -- don't take removed items into account. lo, hi, num_added, num_removed = @start_old, @end_old, 0, 0 outlist = @data_old[lo .. hi].map { |e| e.insert(0, encode(' ')) } @blocks.each do |block| block.remove.each do |item| op = item.action.to_s # - offset = item.position - lo + num_added outlist[offset][0, 1] = encode(op) num_removed += 1 end block.insert.each do |item| op = item.action.to_s # + offset = item.position - @start_new + num_removed outlist[offset, 0] = encode(op) + @data_new[item.position] num_added += 1 end end s << outlist.join(encode("\n")) end private :unified_diff def context_diff s = encode("***************\n") s << encode("*** #{context_range(:old)} ****\n") r = context_range(:new) # Print out file 1 part for each block in context diff format if there # are any blocks that remove items lo, hi = @start_old, @end_old removes = @blocks.select { |e| not e.remove.empty? } if removes outlist = @data_old[lo .. hi].map { |e| e.insert(0, encode(' ')) } removes.each do |block| block.remove.each do |item| outlist[item.position - lo][0, 1] = encode(block.op) # - or ! end end s << outlist.join("\n") end s << encode("\n--- #{r} ----\n") lo, hi = @start_new, @end_new inserts = @blocks.select { |e| not e.insert.empty? } if inserts outlist = @data_new[lo .. hi].collect { |e| e.insert(0, encode(' ')) } inserts.each do |block| block.insert.each do |item| outlist[item.position - lo][0, 1] = encode(block.op) # + or ! end end s << outlist.join("\n") end s end private :context_diff def ed_diff(format) op_act = { "+" => 'a', "-" => 'd', "!" => "c" } warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 if format == :reverse_ed s = encode("#{op_act[@blocks[0].op]}#{context_range(:old)}\n") else s = encode("#{context_range(:old, ' ')}#{op_act[@blocks[0].op]}\n") end unless @blocks[0].insert.empty? @data_new[@start_new .. @end_new].each { |e| s << e + encode("\n") } s << encode(".\n") end s end private :ed_diff # Generate a range of item numbers to print. Only print 1 number if the # range has only one item in it. Otherwise, it's 'start,end' def context_range(mode, op = ',') case mode when :old s, e = (@start_old + 1), (@end_old + 1) when :new s, e = (@start_new + 1), (@end_new + 1) end (s < e) ? "#{s}#{op}#{e}" : "#{e}" end private :context_range # Generate a range of item numbers to print for unified diff. Print number # where block starts, followed by number of lines in the block # (don't print number of lines if it's 1) def unified_range(mode) case mode when :old s, e = (@start_old + 1), (@end_old + 1) when :new s, e = (@start_new + 1), (@end_new + 1) end length = e - s + 1 first = (length < 2) ? e : s # "strange, but correct" (length == 1) ? "#{first}" : "#{first},#{length}" end private :unified_range if String.method_defined?(:encoding) def encode(literal, target_encoding = @preferred_data_encoding) literal.encode target_encoding end def encode_as(string, *args) args.map { |arg| arg.encode(string.encoding) } end else def encode(literal, target_encoding = nil) literal end def encode_as(string, *args) args end end private :encode private :encode_as end diff-lcs-1.3/lib/diff/lcs/htmldiff.rb0000644000004100000410000000617413041652267017473 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'cgi' class Diff::LCS::HTMLDiff class << self attr_accessor :can_expand_tabs #:nodoc: end self.can_expand_tabs = true class Callbacks attr_accessor :output attr_accessor :match_class attr_accessor :only_a_class attr_accessor :only_b_class def initialize(output, options = {}) @output = output options ||= {} @match_class = options[:match_class] || "match" @only_a_class = options[:only_a_class] || "only_a" @only_b_class = options[:only_b_class] || "only_b" end def htmlize(element, css_class) element = " " if element.empty? %Q|
#{element}
\n| end private :htmlize # This will be called with both lines are the same def match(event) @output << htmlize(event.old_element, :match_class) end # This will be called when there is a line in A that isn't in B def discard_a(event) @output << htmlize(event.old_element, :only_a_class) end # This will be called when there is a line in B that isn't in A def discard_b(event) @output << htmlize(event.new_element, :only_b_class) end end DEFAULT_OPTIONS = { :expand_tabs => nil, :output => nil, :css => nil, :title => nil, } DEFAULT_CSS = <<-CSS body { margin: 0; } .diff { border: 1px solid black; margin: 1em 2em; } p { margin-left: 2em; } pre { padding-left: 1em; margin: 0; font-family: Inconsolata, Consolas, Lucida, Courier, monospaced; white-space: pre; } .match { } .only_a { background-color: #fdd; color: red; text-decoration: line-through; } .only_b { background-color: #ddf; color: blue; border-left: 3px solid blue } h1 { margin-left: 2em; } CSS def initialize(left, right, options = nil) @left = left @right = right @options = options @options = DEFAULT_OPTIONS.dup if @options.nil? end def verify_options @options[:expand_tabs] ||= 4 @options[:expand_tabs] = 4 if @options[:expand_tabs] < 0 @options[:output] ||= $stdout @options[:css] ||= DEFAULT_CSS.dup @options[:title] ||= "diff" end private :verify_options attr_reader :options def run verify_options if @options[:expand_tabs] > 0 && self.class.can_expand_tabs formatter = Text::Format.new formatter.tabstop = @options[:expand_tabs] @left.map! { |line| formatter.expand(line.chomp) } @right.map! { |line| formatter.expand(line.chomp) } end @left.map! { |line| CGI.escapeHTML(line.chomp) } @right.map! { |line| CGI.escapeHTML(line.chomp) } @options[:output] << <<-OUTPUT #{@options[:title]}

#{@options[:title]}

Legend: Only in Old  Only in New

OUTPUT callbacks = Callbacks.new(@options[:output]) Diff::LCS.traverse_sequences(@left, @right, callbacks) @options[:output] << <<-OUTPUT
OUTPUT end end diff-lcs-1.3/lib/diff/lcs.rb0000644000004100000410000006255513041652267015703 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- module Diff; end unless defined? Diff # == How Diff Works (by Mark-Jason Dominus) # # I once read an article written by the authors of +diff+; they said that # they hard worked very hard on the algorithm until they found the right # one. # # I think what they ended up using (and I hope someone will correct me, # because I am not very confident about this) was the `longest common # subsequence' method. In the LCS problem, you have two sequences of items: # # a b c d f g h j q z # a b c d e f g i j k r x y z # # and you want to find the longest sequence of items that is present in both # original sequences in the same order. That is, you want to find a new # sequence *S* which can be obtained from the first sequence by deleting # some items, and from the second sequence by deleting other items. You also # want *S* to be as long as possible. In this case *S* is: # # a b c d f g j z # # From there it's only a small step to get diff-like output: # # e h i k q r x y # + - + + - + + + # # This module solves the LCS problem. It also includes a canned function to # generate +diff+-like output. # # It might seem from the example above that the LCS of two sequences is # always pretty obvious, but that's not always the case, especially when the # two sequences have many repeated elements. For example, consider # # a x b y c z p d q # a b c a x b y c z # # A naive approach might start by matching up the +a+ and +b+ that appear at # the beginning of each sequence, like this: # # a x b y c z p d q # a b c a b y c z # # This finds the common subsequence +a b c z+. But actually, the LCS is +a x # b y c z+: # # a x b y c z p d q # a b c a x b y c z module Diff::LCS VERSION = '1.3' end require 'diff/lcs/callbacks' require 'diff/lcs/internals' module Diff::LCS # Returns an Array containing the longest common subsequence(s) between # +self+ and +other+. See Diff::LCS#LCS. # # lcs = seq1.lcs(seq2) def lcs(other, &block) #:yields self[i] if there are matched subsequences: Diff::LCS.lcs(self, other, &block) end # Returns the difference set between +self+ and +other+. See # Diff::LCS#diff. def diff(other, callbacks = nil, &block) Diff::LCS.diff(self, other, callbacks, &block) end # Returns the balanced ("side-by-side") difference set between +self+ and # +other+. See Diff::LCS#sdiff. def sdiff(other, callbacks = nil, &block) Diff::LCS.sdiff(self, other, callbacks, &block) end # Traverses the discovered longest common subsequences between +self+ and # +other+. See Diff::LCS#traverse_sequences. def traverse_sequences(other, callbacks = nil, &block) traverse_sequences(self, other, callbacks || Diff::LCS.YieldingCallbacks, &block) end # Traverses the discovered longest common subsequences between +self+ and # +other+ using the alternate, balanced algorithm. See # Diff::LCS#traverse_balanced. def traverse_balanced(other, callbacks = nil, &block) traverse_balanced(self, other, callbacks || Diff::LCS.YieldingCallbacks, &block) end # Attempts to patch +self+ with the provided +patchset+. A new sequence # based on +self+ and the +patchset+ will be created. See Diff::LCS#patch. # Attempts to autodiscover the direction of the patch. def patch(patchset) Diff::LCS.patch(self, patchset) end alias_method :unpatch, :patch # Attempts to patch +self+ with the provided +patchset+. A new sequence # based on +self+ and the +patchset+ will be created. See Diff::LCS#patch. # Does no patch direction autodiscovery. def patch!(patchset) Diff::LCS.patch!(self, patchset) end # Attempts to unpatch +self+ with the provided +patchset+. A new sequence # based on +self+ and the +patchset+ will be created. See Diff::LCS#unpatch. # Does no patch direction autodiscovery. def unpatch!(patchset) Diff::LCS.unpatch!(self, patchset) end # Attempts to patch +self+ with the provided +patchset+, using #patch!. If # the sequence this is used on supports #replace, the value of +self+ will # be replaced. See Diff::LCS#patch. Does no patch direction autodiscovery. def patch_me(patchset) if respond_to? :replace replace(patch!(patchset)) else patch!(patchset) end end # Attempts to unpatch +self+ with the provided +patchset+, using # #unpatch!. If the sequence this is used on supports #replace, the value # of +self+ will be replaced. See Diff::LCS#unpatch. Does no patch direction # autodiscovery. def unpatch_me(patchset) if respond_to? :replace replace(unpatch!(patchset)) else unpatch!(patchset) end end end class << Diff::LCS def lcs(seq1, seq2, &block) #:yields seq1[i] for each matched: matches = Diff::LCS::Internals.lcs(seq1, seq2) ret = [] string = seq1.kind_of? String matches.each_with_index do |e, i| unless matches[i].nil? v = string ? seq1[i, 1] : seq1[i] v = block[v] if block ret << v end end ret end alias_method :LCS, :lcs # #diff computes the smallest set of additions and deletions necessary to # turn the first sequence into the second, and returns a description of # these changes. # # See Diff::LCS::DiffCallbacks for the default behaviour. An alternate # behaviour may be implemented with Diff::LCS::ContextDiffCallbacks. If a # Class argument is provided for +callbacks+, #diff will attempt to # initialise it. If the +callbacks+ object (possibly initialised) responds # to #finish, it will be called. def diff(seq1, seq2, callbacks = nil, &block) # :yields diff changes: diff_traversal(:diff, seq1, seq2, callbacks || Diff::LCS::DiffCallbacks, &block) end # #sdiff computes all necessary components to show two sequences and their # minimized differences side by side, just like the Unix utility # sdiff does: # # old < - # same same # before | after # - > new # # See Diff::LCS::SDiffCallbacks for the default behaviour. An alternate # behaviour may be implemented with Diff::LCS::ContextDiffCallbacks. If a # Class argument is provided for +callbacks+, #diff will attempt to # initialise it. If the +callbacks+ object (possibly initialised) responds # to #finish, it will be called. def sdiff(seq1, seq2, callbacks = nil, &block) #:yields diff changes: diff_traversal(:sdiff, seq1, seq2, callbacks || Diff::LCS::SDiffCallbacks, &block) end # #traverse_sequences is the most general facility provided by this # module; #diff and #lcs are implemented as calls to it. # # The arguments to #traverse_sequences are the two sequences to traverse, # and a callback object, like this: # # traverse_sequences(seq1, seq2, Diff::LCS::ContextDiffCallbacks.new) # # == Callback Methods # # Optional callback methods are emphasized. # # callbacks#match:: Called when +a+ and +b+ are pointing to # common elements in +A+ and +B+. # callbacks#discard_a:: Called when +a+ is pointing to an # element not in +B+. # callbacks#discard_b:: Called when +b+ is pointing to an # element not in +A+. # callbacks#finished_a:: Called when +a+ has reached the end of # sequence +A+. # callbacks#finished_b:: Called when +b+ has reached the end of # sequence +B+. # # == Algorithm # # a---+ # v # A = a b c e h j l m n p # B = b c d e f j k l m r s t # ^ # b---+ # # If there are two arrows (+a+ and +b+) pointing to elements of sequences # +A+ and +B+, the arrows will initially point to the first elements of # their respective sequences. #traverse_sequences will advance the arrows # through the sequences one element at a time, calling a method on the # user-specified callback object before each advance. It will advance the # arrows in such a way that if there are elements A[i] and # B[j] which are both equal and part of the longest common # subsequence, there will be some moment during the execution of # #traverse_sequences when arrow +a+ is pointing to A[i] and # arrow +b+ is pointing to B[j]. When this happens, # #traverse_sequences will call callbacks#match and then it will # advance both arrows. # # Otherwise, one of the arrows is pointing to an element of its sequence # that is not part of the longest common subsequence. #traverse_sequences # will advance that arrow and will call callbacks#discard_a or # callbacks#discard_b, depending on which arrow it advanced. If # both arrows point to elements that are not part of the longest common # subsequence, then #traverse_sequences will advance one of them and call # the appropriate callback, but it is not specified which it will call. # # The methods for callbacks#match, callbacks#discard_a, # and callbacks#discard_b are invoked with an event comprising # the action ("=", "+", or "-", respectively), the indicies +i+ and +j+, # and the elements A[i] and B[j]. Return values are # discarded by #traverse_sequences. # # === End of Sequences # # If arrow +a+ reaches the end of its sequence before arrow +b+ does, # #traverse_sequence will try to call callbacks#finished_a with # the last index and element of +A+ (A[-1]) and the current index # and element of +B+ (B[j]). If callbacks#finished_a # does not exist, then callbacks#discard_b will be called on each # element of +B+ until the end of the sequence is reached (the call will # be done with A[-1] and B[j] for each element). # # If +b+ reaches the end of +B+ before +a+ reaches the end of +A+, # callbacks#finished_b will be called with the current index and # element of +A+ (A[i]) and the last index and element of +B+ # (A[-1]). Again, if callbacks#finished_b does not exist # on the callback object, then callbacks#discard_a will be called # on each element of +A+ until the end of the sequence is reached # (A[i] and B[-1]). # # There is a chance that one additional callbacks#discard_a or # callbacks#discard_b will be called after the end of the # sequence is reached, if +a+ has not yet reached the end of +A+ or +b+ # has not yet reached the end of +B+. def traverse_sequences(seq1, seq2, callbacks = Diff::LCS::SequenceCallbacks, &block) #:yields change events: callbacks ||= Diff::LCS::SequenceCallbacks matches = Diff::LCS::Internals.lcs(seq1, seq2) run_finished_a = run_finished_b = false string = seq1.kind_of?(String) a_size = seq1.size b_size = seq2.size ai = bj = 0 (0..matches.size).each do |i| b_line = matches[i] ax = string ? seq1[i, 1] : seq1[i] bx = string ? seq2[bj, 1] : seq2[bj] if b_line.nil? unless ax.nil? or (string and ax.empty?) event = Diff::LCS::ContextChange.new('-', i, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) end else loop do break unless bj < b_line bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new('+', i, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new('=', i, ax, bj, bx) event = yield event if block_given? callbacks.match(event) bj += 1 end ai = i end ai += 1 # The last entry (if any) processed was a match. +ai+ and +bj+ point # just past the last matching lines in their sequences. while (ai < a_size) or (bj < b_size) # last A? if ai == a_size and bj < b_size if callbacks.respond_to?(:finished_a) and not run_finished_a ax = string ? seq1[-1, 1] : seq1[-1] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new('>', (a_size - 1), ax, bj, bx) event = yield event if block_given? callbacks.finished_a(event) run_finished_a = true else ax = string ? seq1[ai, 1] : seq1[ai] loop do bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 break unless bj < b_size end end end # last B? if bj == b_size and ai < a_size if callbacks.respond_to?(:finished_b) and not run_finished_b ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[-1, 1] : seq2[-1] event = Diff::LCS::ContextChange.new('<', ai, ax, (b_size - 1), bx) event = yield event if block_given? callbacks.finished_b(event) run_finished_b = true else bx = string ? seq2[bj, 1] : seq2[bj] loop do ax = string ? seq1[ai, 1] : seq1[ai] event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 break unless bj < b_size end end end if ai < a_size ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 end if bj < b_size ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end end end # #traverse_balanced is an alternative to #traverse_sequences. It uses a # different algorithm to iterate through the entries in the computed # longest common subsequence. Instead of viewing the changes as insertions # or deletions from one of the sequences, #traverse_balanced will report # changes between the sequences. # # The arguments to #traverse_balanced are the two sequences to traverse # and a callback object, like this: # # traverse_balanced(seq1, seq2, Diff::LCS::ContextDiffCallbacks.new) # # #sdiff is implemented with #traverse_balanced. # # == Callback Methods # # Optional callback methods are emphasized. # # callbacks#match:: Called when +a+ and +b+ are pointing to # common elements in +A+ and +B+. # callbacks#discard_a:: Called when +a+ is pointing to an # element not in +B+. # callbacks#discard_b:: Called when +b+ is pointing to an # element not in +A+. # callbacks#change:: Called when +a+ and +b+ are pointing to # the same relative position, but # A[a] and B[b] are not # the same; a change has # occurred. # # #traverse_balanced might be a bit slower than #traverse_sequences, # noticable only while processing huge amounts of data. # # == Algorithm # # a---+ # v # A = a b c e h j l m n p # B = b c d e f j k l m r s t # ^ # b---+ # # === Matches # # If there are two arrows (+a+ and +b+) pointing to elements of sequences # +A+ and +B+, the arrows will initially point to the first elements of # their respective sequences. #traverse_sequences will advance the arrows # through the sequences one element at a time, calling a method on the # user-specified callback object before each advance. It will advance the # arrows in such a way that if there are elements A[i] and # B[j] which are both equal and part of the longest common # subsequence, there will be some moment during the execution of # #traverse_sequences when arrow +a+ is pointing to A[i] and # arrow +b+ is pointing to B[j]. When this happens, # #traverse_sequences will call callbacks#match and then it will # advance both arrows. # # === Discards # # Otherwise, one of the arrows is pointing to an element of its sequence # that is not part of the longest common subsequence. #traverse_sequences # will advance that arrow and will call callbacks#discard_a or # callbacks#discard_b, depending on which arrow it advanced. # # === Changes # # If both +a+ and +b+ point to elements that are not part of the longest # common subsequence, then #traverse_sequences will try to call # callbacks#change and advance both arrows. If # callbacks#change is not implemented, then # callbacks#discard_a and callbacks#discard_b will be # called in turn. # # The methods for callbacks#match, callbacks#discard_a, # callbacks#discard_b, and callbacks#change are invoked # with an event comprising the action ("=", "+", "-", or "!", # respectively), the indicies +i+ and +j+, and the elements # A[i] and B[j]. Return values are discarded by # #traverse_balanced. # # === Context # Note that +i+ and +j+ may not be the same index position, even if +a+ # and +b+ are considered to be pointing to matching or changed elements. def traverse_balanced(seq1, seq2, callbacks = Diff::LCS::BalancedCallbacks) matches = Diff::LCS::Internals.lcs(seq1, seq2) a_size = seq1.size b_size = seq2.size ai = bj = mb = 0 ma = -1 string = seq1.kind_of?(String) # Process all the lines in the match vector. loop do # Find next match indices +ma+ and +mb+ loop do ma += 1 break unless ma < matches.size and matches[ma].nil? end break if ma >= matches.size # end of matches? mb = matches[ma] # Change(seq2) while (ai < ma) or (bj < mb) ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] case [(ai < ma), (bj < mb)] when [true, true] if callbacks.respond_to?(:change) event = Diff::LCS::ContextChange.new('!', ai, ax, bj, bx) event = yield event if block_given? callbacks.change(event) ai += 1 bj += 1 else event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 ax = string ? seq1[ai, 1] : seq1[ai] event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end when [true, false] event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 when [false, true] event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end end # Match ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] event = Diff::LCS::ContextChange.new('=', ai, ax, bj, bx) event = yield event if block_given? callbacks.match(event) ai += 1 bj += 1 end while (ai < a_size) or (bj < b_size) ax = string ? seq1[ai, 1] : seq1[ai] bx = string ? seq2[bj, 1] : seq2[bj] case [(ai < a_size), (bj < b_size)] when [true, true] if callbacks.respond_to?(:change) event = Diff::LCS::ContextChange.new('!', ai, ax, bj, bx) event = yield event if block_given? callbacks.change(event) ai += 1 bj += 1 else event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 ax = string ? seq1[ai, 1] : seq1[ai] event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end when [true, false] event = Diff::LCS::ContextChange.new('-', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_a(event) ai += 1 when [false, true] event = Diff::LCS::ContextChange.new('+', ai, ax, bj, bx) event = yield event if block_given? callbacks.discard_b(event) bj += 1 end end end PATCH_MAP = { #:nodoc: :patch => { '+' => '+', '-' => '-', '!' => '!', '=' => '=' }, :unpatch => { '+' => '-', '-' => '+', '!' => '!', '=' => '=' } } # Applies a +patchset+ to the sequence +src+ according to the +direction+ # (:patch or :unpatch), producing a new sequence. # # If the +direction+ is not specified, Diff::LCS::patch will attempt to # discover the direction of the +patchset+. # # A +patchset+ can be considered to apply forward (:patch) if the # following expression is true: # # patch(s1, diff(s1, s2)) -> s2 # # A +patchset+ can be considered to apply backward (:unpatch) if # the following expression is true: # # patch(s2, diff(s1, s2)) -> s1 # # If the +patchset+ contains no changes, the +src+ value will be returned # as either src.dup or +src+. A +patchset+ can be deemed as # having no changes if the following predicate returns true: # # patchset.empty? or # patchset.flatten.all? { |change| change.unchanged? } # # === Patchsets # # A +patchset+ is always an enumerable sequence of changes, hunks of # changes, or a mix of the two. A hunk of changes is an enumerable # sequence of changes: # # [ # patchset # # change # [ # hunk # # change # ] # ] # # The +patch+ method accepts patchsets that are enumerable # sequences containing either Diff::LCS::Change objects (or a subclass) or # the array representations of those objects. Prior to application, array # representations of Diff::LCS::Change objects will be reified. def patch(src, patchset, direction = nil) # Normalize the patchset. has_changes, patchset = Diff::LCS::Internals.analyze_patchset(patchset) if not has_changes return src.dup if src.respond_to? :dup return src end string = src.kind_of?(String) # Start with a new empty type of the source's class res = src.class.new direction ||= Diff::LCS::Internals.intuit_diff_direction(src, patchset) ai = bj = 0 patch_map = PATCH_MAP[direction] patchset.flatten.each do |change| # Both Change and ContextChange support #action action = patch_map[change.action] case change when Diff::LCS::ContextChange case direction when :patch el = change.new_element op = change.old_position np = change.new_position when :unpatch el = change.old_element op = change.new_position np = change.old_position end case action when '-' # Remove details from the old string while ai < op res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end ai += 1 when '+' while bj < np res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end res << el bj += 1 when '=' # This only appears in sdiff output with the SDiff callback. # Therefore, we only need to worry about dealing with a single # element. res << el ai += 1 bj += 1 when '!' while ai < op res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end bj += 1 ai += 1 res << el end when Diff::LCS::Change case action when '-' while ai < change.position res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end ai += 1 when '+' while bj < change.position res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end bj += 1 res << change.element end end end while ai < src.size res << (string ? src[ai, 1] : src[ai]) ai += 1 bj += 1 end res end # Given a set of patchset, convert the current version to the prior # version. Does no auto-discovery. def unpatch!(src, patchset) patch(src, patchset, :unpatch) end # Given a set of patchset, convert the current version to the next # version. Does no auto-discovery. def patch!(src, patchset) patch(src, patchset, :patch) end end diff-lcs-1.3/lib/diff-lcs.rb0000644000004100000410000000006313041652267015663 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'diff/lcs' diff-lcs-1.3/diff-lcs.gemspec0000644000004100000410000000772613041652267016152 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "diff-lcs" s.version = "1.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Austin Ziegler"] s.date = "2017-01-18" s.description = "Diff::LCS computes the difference between two Enumerable sequences using the\nMcIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities\nto create a simple HTML diff output format and a standard diff-like tool.\n\nThis is release 1.3, providing a tentative fix to a long-standing issue related\nto incorrect detection of a patch direction. Also modernizes the gem\ninfrastructure, testing infrastructure, and provides a warning-free experience\nto Ruby 2.4 users." s.email = ["halostatue@gmail.com"] s.executables = ["htmldiff", "ldiff"] s.extra_rdoc_files = ["Code-of-Conduct.md", "Contributing.md", "History.md", "License.md", "Manifest.txt", "README.rdoc", "docs/COPYING.txt", "docs/artistic.txt"] s.files = [".rspec", "Code-of-Conduct.md", "Contributing.md", "History.md", "License.md", "Manifest.txt", "README.rdoc", "Rakefile", "autotest/discover.rb", "bin/htmldiff", "bin/ldiff", "docs/COPYING.txt", "docs/artistic.txt", "lib/diff-lcs.rb", "lib/diff/lcs.rb", "lib/diff/lcs/array.rb", "lib/diff/lcs/block.rb", "lib/diff/lcs/callbacks.rb", "lib/diff/lcs/change.rb", "lib/diff/lcs/htmldiff.rb", "lib/diff/lcs/hunk.rb", "lib/diff/lcs/internals.rb", "lib/diff/lcs/ldiff.rb", "lib/diff/lcs/string.rb", "spec/change_spec.rb", "spec/diff_spec.rb", "spec/fixtures/ds1.csv", "spec/fixtures/ds2.csv", "spec/hunk_spec.rb", "spec/issues_spec.rb", "spec/lcs_spec.rb", "spec/ldiff_spec.rb", "spec/patch_spec.rb", "spec/sdiff_spec.rb", "spec/spec_helper.rb", "spec/traverse_balanced_spec.rb", "spec/traverse_sequences_spec.rb"] s.homepage = "https://github.com/halostatue/diff-lcs" s.licenses = ["MIT", "Artistic-2.0", "GPL-2.0+"] s.rdoc_options = ["--main", "README.rdoc"] s.require_paths = ["lib"] s.required_ruby_version = Gem::Requirement.new(">= 1.8") s.rubygems_version = "1.8.23" s.summary = "Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm" if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q, ["~> 3.16"]) s.add_development_dependency(%q, ["~> 1.0"]) s.add_development_dependency(%q, ["~> 1.1"]) s.add_development_dependency(%q, ["~> 1.6"]) s.add_development_dependency(%q, ["~> 1.0"]) s.add_development_dependency(%q, ["~> 1.2"]) s.add_development_dependency(%q, ["< 12", ">= 10.0"]) s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, ["< 4", ">= 2.0"]) else s.add_dependency(%q, ["~> 3.16"]) s.add_dependency(%q, ["~> 1.0"]) s.add_dependency(%q, ["~> 1.1"]) s.add_dependency(%q, ["~> 1.6"]) s.add_dependency(%q, ["~> 1.0"]) s.add_dependency(%q, ["~> 1.2"]) s.add_dependency(%q, ["< 12", ">= 10.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["< 4", ">= 2.0"]) end else s.add_dependency(%q, ["~> 3.16"]) s.add_dependency(%q, ["~> 1.0"]) s.add_dependency(%q, ["~> 1.1"]) s.add_dependency(%q, ["~> 1.6"]) s.add_dependency(%q, ["~> 1.0"]) s.add_dependency(%q, ["~> 1.2"]) s.add_dependency(%q, ["< 12", ">= 10.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["< 4", ">= 2.0"]) end end diff-lcs-1.3/Code-of-Conduct.md0000644000004100000410000000623613041652267016304 0ustar www-datawww-data# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ diff-lcs-1.3/autotest/0000755000004100000410000000000013041652267014752 5ustar www-datawww-datadiff-lcs-1.3/autotest/discover.rb0000644000004100000410000000004413041652267017113 0ustar www-datawww-dataAutotest.add_discovery { "rspec2" } diff-lcs-1.3/docs/0000755000004100000410000000000013041652267014032 5ustar www-datawww-datadiff-lcs-1.3/docs/COPYING.txt0000644000004100000410000004325413041652267015713 0ustar www-datawww-data GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. diff-lcs-1.3/docs/artistic.txt0000644000004100000410000001372713041652267016427 0ustar www-datawww-dataThe "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End diff-lcs-1.3/History.md0000644000004100000410000002223113041652267015065 0ustar www-datawww-data## 1.3 / 2017-01-18 * Bugs fixed: * Fixed an error for bin/ldiff --version. Fixes [issue #21][]. * Force Diff::LCS::Change and Diff::LCS::ContextChange to only perform equality comparisons against themselves. Provided by Kevin Mook in [pull request #29][]. * Fix tab expansion in htmldiff, provided by Mark Friedgan in [pull request #25][]. * Silence Ruby 2.4 Fixnum deprecation warnings. Fixxues [issue #38][] and [pull request#36][]. * Ensure that test dependencies are loaded properly. Fixes [issue #33][] and [pull request #34][]. * Fix [issue #1][] with incorrect intuition of patch direction. Tentative fix, but the previous failure cases pass now. * Tooling changes: * Added SimpleCov and Coveralls support. * Change the homepage (temporarily) to the GitHub repo. * Updated testing and gem infrastructure. * Modernized the specs. * Cleaned up documentation. * Added a Code of Conduct. ## 1.2.5 / 2013-11-08 * Bugs fixed: * Comparing arrays flattened them too far, especially with Diff::LCS.sdiff. Fixed by Josh Bronson in [pull request #23][]. ## 1.2.4 / 2013-04-20 * Bugs fixed: * A bug was introduced after 1.1.3 when pruning common sequences at the start of comparison. Paul Kunysch (@pck) fixed this in [pull request #18][]. Thanks! * The Rubinius (1.9 mode) bug in [rubinius/rubinius#2268][] has been fixed by the Rubinius team two days after it was filed. Thanks for fixing this so quickly! * Switching to Raggi's hoe-gemspec2 for gemspec generation. ## 1.2.3 / 2013-04-11 * Bugs Fixed: * The new encoding detection for diff output generation (added in 1.2.2) introduced a bug if the left side of the comparison was the empty set. Originally found in [rspec/rspec-expectations#238][] and [rspec/rspec-expectations#239][]. Jon Rowe developed a reasonable heuristic (left side, right side, empty string literal) to avoid this bug. * There is a known issue with Rubinius in 1.9 mode reported in [rubinius/rubinius#2268][] and demonstrated in the Travis CI builds. For all other tested platforms, diff-lcs is considered stable. As soon as a suitably small test-case can be created for the Rubinius team to examine, this will be added to the Rubinius issue around this. ## 1.2.2 / 2013-03-30 * Bugs Fixed: * Diff::LCS::Hunk could not properly generate a difference for comparison sets that are not US-ASCII-compatible because of the use of literal regular expressions and strings. Jon Rowe found this in [rspec/rspec-expectations#219][] and provided a first pass implementation in [pull request #15][]. I've reworked it because of test failures in Rubinius when running in Ruby 1.9 mode. This coerces the added values to the encoding of the old dataset (as determined by the first piece of the old dataset). * Adding Travis CI testing for Ruby 2.0. ## 1.2.1 / 2013-02-09 * Bugs Fixed: * As seen in [rspec/rspec-expectations#200][], the release of Diff::LCS 1.2 introduced an unnecessary public API change to Diff::LCS::Hunk (see the change at [rspec/rspec-expectations@3d6fc82c][] for details). The new method name (and behaviour) is more correct, but I should not have renamed the function or should have at least provided an alias. This release restores Diff::LCS::Hunk#unshift as an alias to #merge. Note that the old #unshift behaviour was incorrect and will not be restored. ## 1.2.0 / 2013-01-21 * Minor Enhancements: * Added special case handling for Diff::LCS.patch so that it handles patches that are empty or contain no changes. * Added two new methods (#patch\_me and #unpatch\_me) to the includable module. * Bugs Fixed: * Fixed [issue #1][] patch direction detection. * Resolved [issue #2][] by handling `string[string.size, 1]` properly (it returns `""` not `nil`). * Michael Granger (ged) fixed an implementation error in Diff::LCS::Change and added specs in [pull request #8][]. Thanks! * Made the code auto-testable. * Vít Ondruch (voxik) provided the latest version of the GPL2 license file in [pull request #10][]. Thanks! * Fixed a documentation issue with the includable versions of #patch! and #unpatch! where they implied that they would replace the original value. Given that Diff::LCS.patch always returns a copy, the documentation was incorrect and has been corrected. To provide the behaviour that was originally documented, two new methods were added to provide this behaviour. Found by scooter-dangle in [issue #12][]. Thanks! * Code Style Changes: * Removed trailing spaces. * Calling class methods using `.` instead of `::`. * Vít Ondruch (voxik) removed unnecessary shebangs in [pull request #9][]. Thanks! * Kenichi Kamiya (kachick) removed some warnings of an unused variable in lucky [pull request #13][]. Thanks! * Embarked on a major refactoring to make the files a little more manageable and understand the code on a deeper level. * Adding to http://travis-ci.org. ## 1.1.3 / 2011-08-27 * Converted to 'hoe' for release. * Converted tests to RSpec 2. * Extracted the body of htmldiff into a class available from diff/lcs/htmldiff. * Migrated development and issue tracking to GitHub. * Bugs fixed: * Eliminated the explicit use of RubyGems in both bin/htmldiff and bin/ldiff. Resolves [issue #4][]. * Eliminated Ruby warnings. Resolves [issue #3][]. ## 1.1.2 / 2004-10-20 * Fixed a problem reported by Mauricio Fernandez in htmldiff. ## 1.1.1 / 2004-09-25 * Fixed bug #891 (Set returned from patch command does not contain last equal part). * Fixed a problem with callback initialisation code (it assumed that all callbacks passed as classes can be initialised; now, it rescues NoMethodError in the event of private :new being called). * Modified the non-initialisable callbacks to have a private #new method. * Moved ldiff core code to Diff::LCS::Ldiff (diff/lcs/ldiff.rb). ## 1.1.0 / - * Eliminated the need for Diff::LCS::Event and removed it. * Added a contextual diff callback, Diff::LCS::ContextDiffCallback. * Implemented patching/unpatching for standard Diff callback output formats with both #diff and #sdiff. * Extensive documentation changes. ## 1.0.4 * Fixed a problem with bin/ldiff output, especially for unified format. Newlines that should have been present weren't. * Changed the .tar.gz installer to generate Windows batch files if ones do not exist already. Removed the existing batch files as they didn't work. ## 1.0.3 * Fixed a problem with #traverse\_sequences where the first difference from the left sequence might not be appropriately captured. ## 1.0.2 * Fixed an issue with ldiff not working because actions were changed from symbols to strings. ## 1.0.1 * Minor modifications to the gemspec, the README. * Renamed the diff program to ldiff (as well as the companion batch file) so as to not collide with the standard diff program. * Fixed issues with RubyGems. Requires RubyGems > 0.6.1 or >= 0.6.1 with the latest CVS version. ## 1.0 * Initial release based mostly on Perl's Algorithm::Diff. [rubinius/rubinius#2268]: https://github.com/rubinius/rubinius/issues/2268 [rspec/rspec-expectations#239]: https://github.com/rspec/rspec-expectations/issues/239 [rspec/rspec-expectations#238]: https://github.com/rspec/rspec-expectations/issues/238 [rspec/rspec-expectations#219]: https://github.com/rspec/rspec-expectations/issues/219 [rspec/rspec-expectations@3d6fc82c]: https://github.com/rspec/rspec-expectations/commit/3d6fc82c [rspec/rspec-expectations#200]: https://github.com/rspec/rspec-expectations/pull/200 [pull request #36]: https://github.com/halostatue/diff-lcs/pull/36 [pull request #34]: https://github.com/halostatue/diff-lcs/pull/34 [pull request #29]: https://github.com/halostatue/diff-lcs/pull/29 [pull request #25]: https://github.com/halostatue/diff-lcs/pull/25 [pull request #23]: https://github.com/halostatue/diff-lcs/pull/23 [pull request #18]: https://github.com/halostatue/diff-lcs/pull/18 [pull request #15]: https://github.com/halostatue/diff-lcs/pull/15 [pull request #13]: https://github.com/halostatue/diff-lcs/pull/13 [pull request #10]: https://github.com/halostatue/diff-lcs/pull/10 [pull request #9]: https://github.com/halostatue/diff-lcs/pull/9 [pull request #8]: https://github.com/halostatue/diff-lcs/pull/8 [issue #38]: https://github.com/halostatue/diff-lcs/issues/38 [issue #33]: https://github.com/halostatue/diff-lcs/issues/33 [issue #21]: https://github.com/halostatue/diff-lcs/issues/21 [issue #12]: https://github.com/halostatue/diff-lcs/issues/12 [issue #4]: https://github.com/halostatue/diff-lcs/issues/4 [issue #3]: https://github.com/halostatue/diff-lcs/issues/3 [issue #2]: https://github.com/halostatue/diff-lcs/issues/2 [issue #1]: https://github.com/halostatue/diff-lcs/issues/1 diff-lcs-1.3/License.md0000644000004100000410000000346413041652267015015 0ustar www-datawww-data== License This software is available under three licenses: the GNU GPL version 2 (or at your option, a later version), the Perl Artistic license, or the MIT license. Note that my preference for licensing is the MIT license, but Algorithm::Diff was dually originally licensed with the Perl Artistic and the GNU GPL ("the same terms as Perl itself") and given that the Ruby implementation originally hewed pretty closely to the Perl version, I must maintain the additional licensing terms. * Copyright 2004–2013 Austin Ziegler. * Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by Mario I. Wolczko. === MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. === Perl Artistic License (version 2) See the file docs/artistic.txt in the main distribution. === GNU GPL version 2 See the file docs/COPYING.txt in the main distribution. diff-lcs-1.3/Contributing.md0000644000004100000410000000520113041652267016071 0ustar www-datawww-data## Contributing I value any contribution to Diff::LCS you can provide: a bug report, a feature request, or code contributions. Code contributions to Diff::LCS are especially welcomeencouraged. Because Diff::LCS is a complex codebase, there are a few guidelines: * Code changes *will not* be accepted without tests. The test suite is written with [RSpec][]. * Match my coding style. * Use a thoughtfully-named topic branch that contains your change. Rebase your commits into logical chunks as necessary. * Use [quality commit messages][]. * Do not change the version number; when your patch is accepted and a release is made, the version will be updated at that point. * Submit a GitHub pull request with your changes. * New or changed behaviours require appropriate documentation. ### Test Dependencies Diff::LCS uses Ryan Davis’s [Hoe][] to manage the release process, and it adds a number of rake tasks. You will mostly be interested in: $ rake which runs the tests the same way that: $ rake spec $ rake travis will do. To assist with the installation of the development dependencies, I have provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file. This will permit you to do: $ bundle install to get the development dependencies. If you aleady have `hoe` installed, you can accomplish the same thing with: $ rake newb This task will install any missing dependencies, run the tests/specs, and generate the RDoc. You can run tests with code coverage analysis by running: $ rake spec:coverage ### Workflow Here's the most direct way to get your work merged into the project: * Fork the project. * Clone down your fork (`git clone git://github.com//diff-lcs.git`). * Create a topic branch to contain your change (`git checkout -b my_awesome_feature`). * Hack away, add tests. Not necessarily in that order. * Make sure everything still passes by running `rake`. * If necessary, rebase your commits into logical chunks, without errors. * Push the branch up (`git push origin my_awesome_feature`). * Create a pull request against halostatue/diff-lcs and describe what your change does and the why you think it should be merged. ### Contributors * Austin Ziegler created Diff::LCS. Thanks to everyone else who has contributed to Diff::LCS: * Kenichi Kamiya * Michael Granger * Vít Ondruch * Jon Rowe * Koichi Ito * Josef Strzibny * Josh Bronson * Mark Friedgan [Rspec]: http://rspec.info/documentation/ [quality commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html [Hoe]: https://github.com/seattlerb/hoe