Add --radix flag, tracing, strict parsing, and broader test coverage#1
Merged
Add --radix flag, tracing, strict parsing, and broader test coverage#1
Conversation
This change establishes a strong correctness contract: **a clean run with no warnings means every input value was successfully parsed and counted**. It introduces a more flexible `--radix` flag, replaces the old `-x` shortcut, and migrates internal logging to `tracing`. ## Breaking changes - **Removed `-x, --hex` flag.** Replaced by `--radix <auto|hex|decimal>` (default: `auto`). To preserve old behavior, use `--radix=hex`. - **`--radix=hex` is strict.** With this flag (or a `0x` prefix), values that fail to parse as hex no longer silently fall back to float -- they warn and contribute `0`. - **New `--radix=decimal`** mode rejects `0x`-prefixed values entirely, useful when input may legitimately contain `0x`-prefixed strings that are not numbers. - **Integer overflow now panics in release builds**, not just debug. Uses `checked_add` to make the behavior consistent across profiles. ## Behavior changes (warnings) Every silently-skipped value now emits a warning, so users can trust that the absence of warnings means a correct sum: - Failed parses (any non-numeric value) now warn. - Field index out of range now warns and skips the line. - Comma stripping (`"1,000"` -> `"1000"`) now warns, surfacing potential locale mismatches (`"1,5"` -> `"15"` is silent no longer). - Large integers that overflow `i128` and fall back to `f64` now warn about possible precision loss. ## Internal changes - Replaced `log` + `env_logger` with `tracing` + `tracing-subscriber` (structured logging, better field formatting). `RUST_LOG` continues to work. - Replaced `std::fs` with `fs-err` for clearer file-open error messages (now includes the path). - Extracted a self-contained `parse_value(&str, Radix)` function with strict-hex semantics. - Various readability cleanups: iterator-based reader setup, flattened reader/line loops, `let-else` for field extraction, simplified verbose output. ## Tests - Added 11 unit tests for `parse_value` covering decimal/hex, integer/float, negatives, scientific notation, hex strictness, invalid input, empty string, and overflow. - Added integration tests for: single-file/multi-file input, nonexistent files, field 0, out-of-range field, negative integers/floats/mixed, comma-formatted numbers, invalid `0x` prefix, large-integer overflow warning, strict hex mode, `--radix=decimal` mode, empty input. ## Verbose output (`-v`) changes - `radix=` now shows `Hex`/`Decimal` instead of `16`/`10`. - Removed `cnt=` field (was unused outside verbose output). - `err=` now contains the warning message rather than the raw `ParseFloatError` debug string. ## Documentation - README updated for the new `--radix` flag, accurate warning examples, and the strict-hex contract.
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.
This change establishes a strong correctness contract: a clean run with no warnings means every input value was successfully parsed and counted. It introduces a more flexible
--radixflag, replaces the old-xshortcut, and migrates internal logging totracing.Breaking changes
-x, --hexflag. Replaced by--radix <auto|hex|decimal>(default:auto). To preserve old behavior, use--radix=hex.--radix=hexis strict. With this flag (or a0xprefix), values that fail to parse as hex no longer silently fall back to float -- they warn and contribute0.--radix=decimalmode rejects0x-prefixed values entirely, useful when input may legitimately contain0x-prefixed strings that are not numbers.checked_addto make the behavior consistent across profiles.Behavior changes (warnings)
Every silently-skipped value now emits a warning, so users can trust that the absence of warnings means a correct sum:
"1,000"->"1000") now warns, surfacing potential locale mismatches ("1,5"->"15"is silent no longer).i128and fall back tof64now warn about possible precision loss.Internal changes
log+env_loggerwithtracing+tracing-subscriber(structured logging, better field formatting).RUST_LOGcontinues to work.std::fswithfs-errfor clearer file-open error messages (now includes the path).parse_value(&str, Radix)function with strict-hex semantics.let-elsefor field extraction, simplified verbose output.Tests
parse_valuecovering decimal/hex, integer/float, negatives, scientific notation, hex strictness, invalid input, empty string, and overflow.0xprefix, large-integer overflow warning, strict hex mode,--radix=decimalmode, empty input.Verbose output (
-v) changesradix=now showsHex/Decimalinstead of16/10.cnt=field (was unused outside verbose output).err=now contains the warning message rather than the rawParseFloatErrordebug string.Documentation
--radixflag, accurate warning examples, and the strict-hex contract.