Repository navigation
diff: use the largest context length given, like GNU diff - #341
qodelicious wants to merge 2 commits into
Conversation
| } | ||
|
|
||
| #[test] | ||
| fn largest_context_count_wins() { |
There was a problem hiding this comment.
please move them to tests/by-util/test_diff.rs , with the -U1 -u case from the issue
There was a problem hiding this comment.
Moved them to tests/by-util/test_diff.rs and added the -U1 -u case from the issue. The expected hunk headers match what GNU diff 3.10 prints for the same files.
| (vec!["-C1", "-c"], 3), | ||
| (vec!["-c", "-C1"], 3), | ||
| (vec!["-C", "7", "-C2"], 7), | ||
| (vec!["--unified=1", "--unified"], 3), |
There was a problem hiding this comment.
could you please also cover --context=1 --context and the -5u form?
There was a problem hiding this comment.
Added both, plus --context --context=1 and -5c. --context=1 --context ends up with 3 lines and -5u with 5, same as GNU.
|
thanks for working on this! |
Cover the -U1 -u case from uutils#340, --context=1 --context and the -5u form, with the expected hunks checked against GNU diff 3.10.
74e4f83 to
59741a1
Compare
|
pre-commit.ci was red because of a merge conflict with main, not a lint error. Rebased and it's green now. Ran the whole upstream suite on main and on this branch. Both give 19 pass, 10 fail, 4 skip, and the output is identical for every test. None of the upstream tests use two context lengths though, so the new test in test_diff.rs is what covers this. |
When more than one context length is given, GNU diff uses the biggest, and a bare -u or -c counts as 3. We kept the last number given and ignored a bare -u or -c, so
-U1 -ugave 1 line of context instead of 3, and-U2 -U1gave 1 instead of 2.Now the parser keeps the largest one. Added a unit test with a few orders of -u/-U and -c/-C, checked against GNU diff 3.10.
Fixes #340