feat(config): add validation for out-of-range config values#43
Conversation
phlx0
left a comment
There was a problem hiding this comment.
The core idea is good. Load() is the right place for this and collecting all errors instead of failing on the first one is the right approach.
Three things to fix before this can merge:
Portuguese comments again (Cenário, Ação, Validação) — please use English, same note as on #41.
Missing CHANGELOG.md entry under ## [Unreleased].
Inconsistent coverage is the main concern. The PR validates rain.density, life.density, waveform.amplitude and pipes.turn_chance but leaves out starfield.count, orrery.bodies, pipes.heads, particles.count and all the speed and reset_seconds fields. A user setting starfield.count = -5 or orrery.bodies = 0 would still get silent unexpected behavior. Either cover everything with meaningful bounds or add a comment explaining why certain fields are intentionally excluded. As written it gives a false sense of safety.
147030c to
b83d7ba
Compare
Closes phlx0#42 Adds Validate() to Config, called by Load() after TOML decoding. Collects all invalid fields into a single multi-line error rather than failing on the first. Covers every numeric field with meaningful bounds across all scenes including starfield.
b83d7ba to
5ccc7b1
Compare
Summary
Closes #42
Adds a
Validate()method toConfigthat checks value ranges after TOML decoding:engine.fps: 1–120engine.cycle_seconds: >= 0scene.rain.density: 0.0–1.0scene.life.density: 0.0–1.0scene.waveform.amplitude: 0.0–1.0scene.pipes.turn_chance: 0.0–1.0Returns a clear multi-line error listing all invalid fields at once (not just the first one).
Includes table-driven tests for every validated field plus a test confirming defaults pass.
Test plan
go vet ./...passesgo test ./...passes — including 7 out-of-range subtests and defaults validation