From 06ee20e929656d41c301f61fd447105c3840e410 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Tue, 6 May 2014 00:08:02 -0400 Subject: diff-lcs 1.3 - Updated testing and gem infrastructure. - Cleaning up documentation. - Modernizing specs. - Silence Ruby 2.4 Fixnum deprecation warnings. Fixes #36, #38. - Ensure test dependencies are loaded. Fixes #33, #34 so that specs can be run independently. - Fix issue #1 with incorrect intuition of patch direction. Tentative fix, but the failure cases pass now. --- lib/diff/lcs/internals.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib/diff/lcs/internals.rb') diff --git a/lib/diff/lcs/internals.rb b/lib/diff/lcs/internals.rb index 9d9e3f3..17d1d06 100644 --- a/lib/diff/lcs/internals.rb +++ b/lib/diff/lcs/internals.rb @@ -142,8 +142,6 @@ class << Diff::LCS::Internals # 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. - # - # Note: This will be deprecated as a public function in a future release. def intuit_diff_direction(src, patchset, limit = nil) string = src.kind_of?(String) count = left_match = left_miss = right_match = right_miss = 0 @@ -217,19 +215,27 @@ class << Diff::LCS::Internals no_left = (left_match == 0) && (left_miss > 0) no_right = (right_match == 0) && (right_miss > 0) - case [no_left, no_right] - when [false, true] + case [ no_left, no_right ] + when [ false, true ] :patch - when [true, false] + when [ true, false ] :unpatch else case left_match <=> right_match when 1 - :patch + if left_miss.zero? + :patch + else + :unpatch + end when -1 - :unpatch + if right_miss.zero? + :unpatch + else + :patch + end else - raise "The provided patchset does not appear to apply to the provided value as either source or destination value." + raise "The provided patchset does not appear to apply to the provided enumerable as either source or destination value." end end end -- cgit v1.2.1