Skip to content

Create the side-by-side option (-y) feature for the diff command (Incomplete) #117

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sami-daniel
Copy link

  • Create the function, in the utils package, limited_string that allows you to truncate a string based on a delimiter (May break the encoding of the character where it was cut)

  • Create tests for limited_string function

  • Add support for -y and --side-by-side flags that enables diff output for side-by-side mode

  • Create implementation of the diff -y (SideBySide) command, base command for sdiff, using the crate diff as engine. Currently it does not fully represent GNU diff -y, some flags (|, (, ), , /) could not be developed due to the limitation of the engine we currently use (crate diff), which did not allow perform logic around it. Only the use of '<' and '>' were enabled.

  • Create tests for SideBySide implementation

TL;DR

A new limited_string function was added to the utils package, allowing strings to be truncated based on a delimiter (note: this may break character encoding at the cut point). Unit tests were created to ensure correct behavior of the function.

Support for the -y and --side-by-side flags was added to enable side-by-side diff output. The SideBySide implementation, serving as the base for the sdiff command, was developed using the diff crate as the comparison engine. Due to limitations of the crate, only the < and > markers are currently supported—other markers like |, (, ),\ and / could not be implemented.

Tests were also created to validate the behavior of the SideBySide mode.

Clarification
The main goal of the limited_string function is to simplify and standardize the process of truncating strings for everyone working on the project. The idea was to provide a utility that anyone could use without having to reimplement or worry too much about string manipulation logic. However, a known limitation of the current implementation is that it can break character encoding, especially when the cut happens mid-way through a multi-byte character (e.g., in UTF-8).

I am open to suggestions on how to improve or safely handle encoding, whether by detecting boundaries or using a safer string-splitting strategy that respects character integrity.

Regarding the SideBySide implementation: I recognize that the output and edit script provided by the diff crate is limited. These limitations currently prevent us from supporting additional characters such as |, (, ), , or / that are used in GNU diff -y to more accurately reflect changes in lines.

For this initial version, I think the use of < and >, are sufficient for a first pass of side-by-side comparison. Moving forward, I did like to open a follow-up issue where we can evaluate better strategies (possibly even considering another diff engine) to handle richer diff representations and support for the missing symbols.

Suggestions and ideas are very welcome!

…omplete).

- Create the function, in the utils package, limited_string that allows you to truncate a string based on a
delimiter (May break the encoding of the character where it was cut)

- Create tests for limited_string function

- Add support for -y and --side-by-side flags that enables diff output for side-by-side mode

- Create implementation of the diff -y (SideBySide) command, base command for sdiff, using the crate
diff as engine. Currently it does not fully represent GNU diff -y, some flags (|, (, ), , /) could
not be developed due to the limitation of the engine we currently use (crate diff), which did not
allow perform logic around it. Only the use of '<' and '>' were enabled.

- Create tests for SideBySide implementation
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 39.02439% with 75 lines in your changes missing coverage. Please review.

Project coverage is 83.71%. Comparing base (978390c) to head (dc6e8fb).

Files with missing lines Patch % Lines
src/side_diff.rs 0.00% 68 Missing ⚠️
src/params.rs 28.57% 5 Missing ⚠️
src/diff.rs 0.00% 1 Missing ⚠️
src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #117      +/-   ##
==========================================
- Coverage   84.69%   83.71%   -0.99%     
==========================================
  Files          12       13       +1     
  Lines        5625     5746     +121     
  Branches      476      479       +3     
==========================================
+ Hits         4764     4810      +46     
- Misses        846      919      +73     
- Partials       15       17       +2     
Flag Coverage Δ
macos_latest 83.73% <39.02%> (-0.95%) ⬇️
ubuntu_latest 83.83% <39.02%> (-0.96%) ⬇️
windows_latest 22.97% <0.81%> (-0.49%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sami-daniel
Copy link
Author

I'll fix the alerts before reopening the PR, 😁

@sami-daniel sami-daniel reopened this Apr 22, 2025
@sami-daniel
Copy link
Author

Is done : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant