Commit 502f3b1
authored
sort:Align sort debug key annotations with GNU coreutils (uutils#9468)
* fix: ignore NUL bytes in sort debug output alignment calculations
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.
* feat: add locale-aware tests for sort debug key 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.
* refactor(test): optimize string building in debug_key_annotation_output 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.
* refactor(tests): improve formatting and readability in sort test helpers
- 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
* refactor(test): embed expected debug key annotation outputs as constants
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.
* feat(sort): extract count_non_null_bytes for debug alignment
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.1 parent 3edf14e commit 502f3b1
2 files changed
+418
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
| |||
670 | 675 | | |
671 | 676 | | |
672 | 677 | | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
673 | 681 | | |
674 | | - | |
| 682 | + | |
| 683 | + | |
675 | 684 | | |
676 | 685 | | |
677 | 686 | | |
678 | 687 | | |
679 | 688 | | |
680 | | - | |
| 689 | + | |
| 690 | + | |
681 | 691 | | |
682 | 692 | | |
683 | 693 | | |
| |||
0 commit comments