diff options
author | Austin Ziegler <austin@zieglers.ca> | 2020-06-28 14:59:37 -0400 |
---|---|---|
committer | Austin Ziegler <austin@zieglers.ca> | 2020-06-28 15:10:04 -0400 |
commit | 2a9a662142d0e62337f4e8c92abca41ebf42cf59 (patch) | |
tree | 6997f89789c2cf340bf6a63c01ae7c479ab2db77 | |
parent | 20ea8f2a77b544c4aa8af1522102475ceeb9fff2 (diff) | |
download | diff-lcs-fix-ruby-1.8-support.tar.gz |
Fix some issues with 1.4 on older Rubiesfix-ruby-1.8-support
- Required to fully support rspec.
- Resolves #63.
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | Rakefile | 21 | ||||
-rw-r--r-- | lib/diff/lcs.rb | 2 | ||||
-rw-r--r-- | lib/diff/lcs/hunk.rb | 2 | ||||
-rw-r--r-- | spec/ldiff_spec.rb | 18 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 |
6 files changed, 40 insertions, 11 deletions
@@ -8,9 +8,13 @@ source 'https://rubygems.org/' if RUBY_VERSION < '1.9' gem 'rake', '< 11' gem 'rdoc', '< 4' + gem 'hoe', '~> 3.20' + + gem 'ruby-debug' elsif RUBY_VERSION >= '2.0' if RUBY_ENGINE == 'ruby' gem 'simplecov', '~> 0.18' + gem 'byebug' end end @@ -6,10 +6,27 @@ 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 + +if RUBY_VERSION < '1.9' + class Array + def to_h + Hash[*self.flatten(1)] + end + end + + class Gem::Specification + def metadata=(*) + end + end + + class Object + def caller_locations(*) + [] + end + end +end _spec = Hoe.spec 'diff-lcs' do developer('Austin Ziegler', 'halostatue@gmail.com') diff --git a/lib/diff/lcs.rb b/lib/diff/lcs.rb index 1fce946..9d47064 100644 --- a/lib/diff/lcs.rb +++ b/lib/diff/lcs.rb @@ -49,7 +49,7 @@ module Diff; end unless defined? Diff # rubocop:disable Style/Documentation # a x b y c z p d q # a b c a x b y c z module Diff::LCS - VERSION = '1.4.2' + VERSION = '1.4.3' end require 'diff/lcs/callbacks' diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index c6b3b25..d884a1b 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -20,7 +20,7 @@ class Diff::LCS::Hunk before = after = file_length_difference after += @blocks[0].diff_size @file_length_difference = after # The caller must get this manually - @max_diff_size = @blocks.lazy.map { |e| e.diff_size }.max + @max_diff_size = @blocks.map { |e| e.diff_size }.max # 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 diff --git a/spec/ldiff_spec.rb b/spec/ldiff_spec.rb index 74bb92d..2f4c235 100644 --- a/spec/ldiff_spec.rb +++ b/spec/ldiff_spec.rb @@ -10,10 +10,10 @@ RSpec.describe 'bin/ldiff' do let(:output_diff_e) { read_fixture('-e') } let(:output_diff_f) { read_fixture('-f') } let(:output_diff_u) { read_fixture('-u') } - let(:output_diff_chef) { read_fixture('-u', base: 'output.diff.chef') } + let(:output_diff_chef) { read_fixture('-u', :base => 'output.diff.chef') } specify do - expect(run_ldiff('-u', left: 'old-chef', right: 'new-chef')).to eq(output_diff_chef) + expect(run_ldiff('-u', :left => 'old-chef', :right => 'new-chef')).to eq(output_diff_chef) end specify do @@ -36,8 +36,11 @@ RSpec.describe 'bin/ldiff' do expect(run_ldiff('-u')).to eq(output_diff_u) end - def read_fixture(flag = nil, base: 'output.diff') - clean_data(IO.binread("spec/fixtures/ldiff/#{base}#{flag}"), flag) + def read_fixture(flag = nil, options = {}) + base = options.fetch(:base, 'output.diff') + name = "spec/fixtures/ldiff/#{base}#{flag}" + data = IO.__send__(IO.respond_to?(:binread) ? :binread : :read, name) + clean_data(data, flag) end def clean_data(data, flag) @@ -69,11 +72,14 @@ RSpec.describe 'bin/ldiff' do ) end - def run_ldiff(flag = nil, left: 'aX', right: 'bXaX') + def run_ldiff(flag = nil, options = {}) + left = options.fetch(:left, 'aX') + right = options.fetch(:right, 'bXaX') stdout, stderr = capture_subprocess_io do system("ruby -Ilib bin/ldiff #{flag} spec/fixtures/#{left} spec/fixtures/#{right}") end - expect(stderr).to be_empty + + expect(stderr).to be_empty if RUBY_VERSION >= '1.9' expect(stdout).not_to be_empty clean_data(stdout, flag) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4286129..b1935d0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,9 @@ require 'rubygems' require 'pathname' -require 'psych' + +require 'psych' if RUBY_VERSION >= '1.9' + if ENV['COVERAGE'] require 'simplecov' |