Impacted version
bundle exec ldiff --version
ldiff 1.5.1
Context
While some attempts to fix the ranges already occured around versions 1.4.
The ranges are still incorrect, and the tests created for #60 are actually incorrect (not helping to fix the behavior).
It seems the fix mostly relies on the last parameter that is used to correct the indexes of the last hunk but this means user has to pass this to get proper ranges. Also it would theoretically means (not verified) that only the last hunk is properly fixed.
As a user of the lib, I would like the range to be properly computed in most cases, without need of the last parameter.
IMHO: the last parameter is mostly (only?) useful to determine whether we should or not output No newline at end of file.
Repro
Let's create 2 files old & new as specified in the non-regression test of #60.
cat old
{
"name": "x",
"description": "hi"
}
and
cat new
{
"name": "x",
"description": "lo"
}
Now let's compare them as described in the test:
old_data = ::File.read('old').lines.map(&:chomp)
new_data = ::File.read('new').lines.map(&:chomp)
diffs = ::Diff::LCS.diff(old_data, new_data)
hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0)
puts hunk.diff(:unified)
Current result
Here is what we get:
@@ -1,5 +1,5 @@
{
"name": "x",
- "description": "hi"
+ "description": "lo"
}
Expected result
Here the old & new lengths are 5 while it should be 4:
@@ -1,4 +1,4 @@
{
"name": "x",
- "description": "hi"
+ "description": "lo"
}
More
Impacted version
Context
While some attempts to fix the ranges already occured around versions 1.4.
The ranges are still incorrect, and the tests created for #60 are actually incorrect (not helping to fix the behavior).
It seems the fix mostly relies on the
lastparameter that is used to correct the indexes of the last hunk but this means user has to pass this to get proper ranges. Also it would theoretically means (not verified) that only the last hunk is properly fixed.As a user of the lib, I would like the range to be properly computed in most cases, without need of the
lastparameter.IMHO: the
lastparameter is mostly (only?) useful to determine whether we should or not outputNo newline at end of file.Repro
Let's create 2 files
old&newas specified in the non-regression test of #60.and
Now let's compare them as described in the test:
Current result
Here is what we get:
Expected result
Here the old & new lengths are
5while it should be4:More
contextformat