Repository navigation
Count unchanged lines in Text Comparison - #22
Open
SakarPaisen wants to merge 1 commit into
Open
SakarPaisen wants to merge 1 commit into
SakarPaisen wants to merge 1 commit into
Conversation
compare_text now reports unchanged_lines, the size of the equal opcodes in the alignment it already builds, so the diff string and the added/removed counts are unchanged. Tests cover the documented replacement example, identical and empty input, entirely different input, line-ending normalization, and repeated lines where the alignment is ambiguous.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #5.
compare_textnow returnsunchanged_lines, counted from theequalopcodes of the alignment it already builds. The unifieddiffstring and theadded_lines/removed_linescounts are untouched.Scope
src/mcp_tools_lab/tools/diff.py— one counter fortag == "equal", usingold_end - old_start, plus a docstring line.tests/test_diff.py— five new tests.docs/tool-guide.md— describes the field and theadded_lines + unchanged_lines == lines in afterinvariant.Tests added
"hello\nold"vs"hello\nnew"→unchanged_lines=1,added_lines=1,removed_lines=1.2; two empty inputs →0.0."same\r\n"vs"same"→1, so the existing newline normalization applies to the count too."a\nb\nb\nc"vs"a\nb\nc\nc"→unchanged_lines=3,added_lines=1,removed_lines=1. I checked this against the realSequenceMatcheralignment instead of assuming where the repeatedb/cpair up.Checks
python -m pytest tests/test_diff.py -q— 7 passedpython -m pytest -q— 67 passedpython .github/scripts/check_rules.py—Scanned 11 files under src/ for print() and network imports: OKPython: 3.13 on Windows 11.
Open item for the maintainers: if the case-insensitive comparison change (#13) adds an
ignore_caseoption later, this count should follow the same comparison mode; the brief for #13 already says so. I left that out of scope here.(Full disclosure: I used an AI coding assistant for this change, and I reviewed and verified everything submitted here.)