-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
sort:Align sort debug key annotations with GNU coreutils #9468
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
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: |
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
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: |
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