Skip to content

Add --radix flag, tracing, strict parsing, and broader test coverage#1

Merged
devjgm merged 1 commit intomainfrom
radix-flag
Apr 26, 2026
Merged

Add --radix flag, tracing, strict parsing, and broader test coverage#1
devjgm merged 1 commit intomainfrom
radix-flag

Conversation

@devjgm
Copy link
Copy Markdown
Owner

@devjgm devjgm commented Apr 26, 2026

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 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.
@devjgm devjgm merged commit 1c403a9 into main Apr 26, 2026
3 checks passed
@devjgm devjgm deleted the radix-flag branch April 26, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant