Commit b79994f
committed
Add --radix flag, tracing, strict parsing, and broader test coverage
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.1 parent 8afa30a commit b79994f
5 files changed
Lines changed: 452 additions & 143 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | | - | |
18 | | - | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | | - | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | | - | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
69 | | - | |
| 74 | + | |
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
| |||
78 | 83 | | |
79 | 84 | | |
80 | 85 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
| |||
161 | 166 | | |
162 | 167 | | |
163 | 168 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
167 | 173 | | |
168 | 174 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
178 | 183 | | |
179 | 184 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 185 | + | |
| 186 | + | |
184 | 187 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 188 | + | |
| 189 | + | |
191 | 190 | | |
192 | 191 | | |
193 | 192 | | |
194 | 193 | | |
195 | 194 | | |
196 | | - | |
197 | | - | |
| 195 | + | |
198 | 196 | | |
199 | | - | |
| 197 | + | |
200 | 198 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
205 | 203 | | |
206 | 204 | | |
207 | 205 | | |
| |||
212 | 210 | | |
213 | 211 | | |
214 | 212 | | |
215 | | - | |
216 | | - | |
| 213 | + | |
217 | 214 | | |
218 | | - | |
| 215 | + | |
219 | 216 | | |
220 | 217 | | |
221 | 218 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
81 | 101 | | |
0 commit comments