feat(version): port rpm-style version comparison from ZETA

This commit is contained in:
2026-08-08 17:22:06 -04:00
parent 348f0e3bac
commit c545879115
3 changed files with 421 additions and 0 deletions
+40
View File
@@ -6,6 +6,46 @@ _Auto-scaffolded by /start-work. Append new entries below - never overwrite._
---
## Task 5 — tofu.vercmp (RPM-style version comparison)
### Module naming
- `version` is a D reserved keyword (conditional compilation). Module is named
`tofu.vercmp`, file `src/tofu/vercmp.d`. The `DepConstraint` struct in
`types.d` uses field `ver` (not `version`) for the same reason.
### Algorithm (exact port from ZETA/lib/vercmp.lua)
- `nextSegment`: skips any non-digit/non-letter chars (separators); then reads
a contiguous run of same-type chars. Returns `(segment, nextIndex)`.
- `cmpNumeric`: strips leading zeros from both segments (`"007"` → `"7"`,
`"000"` → `"0"`). Longer stripped string wins; then lexicographic.
- `compare`: strips all whitespace, then loops over alternating segments.
If both segments are digit-typed → `cmpNumeric`, else lexical. When one
version exhausts segments: the exhausted one is *older* (shorter = older).
This matches RPM semantics: `compare("1.0.0", "1.0") > 0`.
- `satisfies`: uses `final switch` on `DepOp` enum. Maps to `compare` result
as expected (ge→c>=0, le→c<=0, eq→c==0, ne→c!=0, gt→c>0, lt→c<0).
- `parseDep`: delegates to `DepConstraint.parse` (already ported in types.d by
task 4). Both implementations are kept consistent.
### whitespace stripping
- Could not use `filter`+`array` because Phobos auto-decodes `string` to
`dchar` range elements, returning `dchar[]` not `string`. Implemented a
manual `removeWhitespace` helper using raw code-unit indexing, with a
`@trusted` cast since the freshly-allocated `char[]` has no aliasing.
### Test porting
- All 10 ZETA test categories ported as separate `@safe unittest` blocks.
- 4 modules pass unittests (types, vercmp, plus pre-existing ones).
- `dub build` passes with warnings-as-errors enabled.
### Future considerations
- When task 12 (constraint resolution) imports `tofu.vercmp`, the `compare`
and `satisfies` functions are ready. The `parseDep` integration with
`DepConstraint.parse` ensures consistency between ZETA and tofu's dep
constraint semantics.
---
## Task 2: Config Loading (src/tofu/config.d)
### toml package API (v1.0.0, Kripth/toml)