Add <=, >=, str, and from-string negative tests#4
Conversation
- Add explicit <= and >= comparison functions - Add str implementation (with tag support) - Add from-string negative test cases: empty string, single number, major.minor only, non-numeric input
There was a problem hiding this comment.
Build & Tests
CI: Failing on both macOS and Ubuntu. The Lint step fails — angler flags nested-if-chain warnings in the existing < function (semver.carp:40-44) and exits with code 1.
The warnings are about pre-existing code (the < function wasn't changed by this PR), but CI is red regardless.
Local build: Carp compiler not available on review machine. CI verified.
Findings
1. CI lint failure must be fixed (semver.carp:39-46)
The < function uses nested if chains that angler flags as [nested-if-chain]. Fix by converting to cond:
(defn < [a b]
(cond
(< (major a) (major b)) true
(> (major a) (major b)) false
(< (minor a) (minor b)) true
(> (minor a) (minor b)) false
(< (patch a) (patch b))))
2. Missing implements for <= and >= (semver.carp:52-54)
The existing < and > have (implements < Semver.<) / (implements > Semver.>), but the new <= and >= do not. For consistency and interface dispatch, add:
(implements <= Semver.<=)
(implements >= Semver.>=)
3. <= and >= logic is correct (semver.carp:52-54)
(not (< b a)) for <= and (not (< a b)) for >= are the standard definitions. Good.
4. str is correct (semver.carp:56-63)
Properly handles both Nothing and Just tags. The implements str is present. Round-trips correctly with from-string (the tag includes the leading -).
5. Confusing test descriptions (tests/semver.carp:76-80, 91-95)
The test labelled "<= is false when greater" actually tests >= (operator on line 80). Similarly, ">= is false when less" tests <= (line 95). Both are logically sound (testing the dual), but the descriptions are misleading. Consider either:
- Renaming to match the operator used:
">= is true when greater"/"<= is true when less" - Or using a different assertion approach to directly test the false case
6. from-string negative tests are good (tests/semver.carp:104-119)
All four cases ("", "1", "1.2", "a.b.c") correctly return Nothing. Good coverage.
Verdict: revise
CI is failing. Fix the lint issue (convert nested if to cond in <), add implements for <=/>=, and clean up the test descriptions.
| (defn <= [a b] (not (< b a))) | ||
|
|
||
| (defn >= [a b] (not (< a b))) | ||
|
|
There was a problem hiding this comment.
<= and >= are already implemented as generic functions.
Summary
<=and>=comparison functions to theSemvermodule, defined in terms of<(matching the pattern used by>)strimplementation that formats as"1.2.3"or"1.2.3-tag", implementing thestrinterfacefrom-stringnegative test cases: empty string, single number, major.minor only, and non-numeric input<=and>=(less, equal, and greater cases)str(with and without tag)All 25 tests pass (up from 13).
Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.