Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues with 1.4 on older Rubies #64

Merged
merged 1 commit into from Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -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'
halostatue marked this conversation as resolved.
Show resolved Hide resolved
elsif RUBY_VERSION >= '2.0'
if RUBY_ENGINE == 'ruby'
gem 'simplecov', '~> 0.18'
gem 'byebug'
end
end

Expand Down
21 changes: 19 additions & 2 deletions Rakefile
Expand Up @@ -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
halostatue marked this conversation as resolved.
Show resolved Hide resolved
def to_h
Hash[*self.flatten(1)]
end
end

class Gem::Specification
halostatue marked this conversation as resolved.
Show resolved Hide resolved
def metadata=(*)
end
end

class Object
def caller_locations(*)
halostatue marked this conversation as resolved.
Show resolved Hide resolved
[]
end
end
end

_spec = Hoe.spec 'diff-lcs' do
developer('Austin Ziegler', 'halostatue@gmail.com')
Expand Down
2 changes: 1 addition & 1 deletion lib/diff/lcs.rb
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/diff/lcs/hunk.rb
Expand Up @@ -20,7 +20,7 @@ def initialize(data_old, data_new, piece, flag_context, file_length_difference)
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
Expand Down
18 changes: 12 additions & 6 deletions spec/ldiff_spec.rb
Expand Up @@ -10,10 +10,10 @@
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
Expand All @@ -36,8 +36,11 @@
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)
Expand Down Expand Up @@ -69,11 +72,14 @@ def clean_output_timestamp(data)
)
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
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -2,7 +2,9 @@

require 'rubygems'
require 'pathname'
require 'psych'

require 'psych' if RUBY_VERSION >= '1.9'


if ENV['COVERAGE']
require 'simplecov'
Expand Down