sort:Align sort debug key annotations with GNU coreutils#9468
Merged
sylvestre merged 11 commits intouutils:mainfrom Dec 24, 2025
Merged
sort:Align sort debug key annotations with GNU coreutils#9468sylvestre merged 11 commits intouutils:mainfrom
sylvestre merged 11 commits intouutils:mainfrom
Conversation
Replaced direct length checks with filtered counts excluding b'\0' in debug underline and indentation output to prevent misalignment from embedded NUL characters, which are often stripped during inspection. Added comprehensive tests for various sort modes and inputs, including NUL byte scenarios, to verify correct debug annotations.
Split the existing `test_debug_key_annotations` into two tests: one for basic functionality and another for locale-specific behavior to handle conditional execution based on environment variables. Extracted a new helper function `debug_key_annotation_output` to generate debug output, improving test modularity and reducing code duplication. This enhances test coverage for debug key annotations in different numeric locales.
|
GNU testsuite comparison: |
…ut for efficiency Rework the `number` helper function to use a mutable String buffer with `writeln!` macro instead of collecting intermediary vectors with `map` and `collect`. This reduces allocations and improves performance in test output generation, building the numbered output directly without extra string concatenations.
- Reformatted command-line arguments in test_debug_key_annotations_locale to fit on fewer lines - Wrapped run_sort calls in debug_key_annotation_output for better code structure - Minor reordering of output.push_str blocks for consistency and clarity
Replace fixture file reads with inline constants in test functions for debug key annotations and locale variants. This makes the tests more self-contained by removing dependencies on external fixture files.
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
sylvestre
reviewed
Dec 5, 2025
src/uu/sort/src/sort.rs
Outdated
| // via `tr -d '\0'`) before inspection. | ||
| let select = &line[..selection.start]; | ||
| write!(writer, "{}", " ".repeat(select.len()))?; | ||
| let indent = select.iter().filter(|&&c| c != b'\0').count(); |
Contributor
There was a problem hiding this comment.
please create a function for the filter
something like
fn count_non_null_bytes(bytes: &[u8]) -> usize {
bytes.iter().filter(|&&c| c != b'\0').count()
}
Add a helper function `count_non_null_bytes` to count bytes in a slice while ignoring embedded NULs. This improves code reusability and is used in debug underline output to ensure proper alignment by filtering NUL characters that may be present in selection strings. Replaces inline counting logic in two locations within the `Line` implementation.
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
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.
Summary:
Add comprehensive fixture files for sort --debug key annotation output, including locale-specific expectations.
Refactor tests to share a helper and split locale-aware coverage, matching GNU sort’s behavior.
Ensure “no match for key” annotations render identically to the reference shell script.
related
#9127