Skip to content

Commit fe4b51c

Browse files
fix(lint): replace 3.14 test literals with 2.5 to clear clippy::approx_constant (refs #22) (#23)
`clippy::approx_constant` is denied-by-default; the five `3.14` literals in lib/common test asserts (math.rs:268, string.rs:300, types.rs:297, types.rs:304) were tripping it and causing `cargo clippy -p my-lang --lib --tests --no-deps` to exit non-zero, which is a CI gate hazard for any future `-D warnings` rollout. None of the affected sites were testing pi specifically -- the literal was incidental. Swapping to `2.5` keeps the tests round-trip-clean (parses to itself, formats to itself, exact in IEEE-754) without approximating any well-known constant. Verified with `cargo test -p my-lang --lib library::common::` (39/39 pass, including the four affected tests). The wider lib test suite is not runnable on clean main yet -- it crashes with STATUS_STACK_BUFFER_OVERRUN on the depth-overflow tests fixed in #21, which is why this PR scopes verification to the affected module. Part 1 of 4 from #22.
1 parent e0e6b6b commit fe4b51c

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

crates/my-lang/lib/common/math.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ mod tests {
265265
fn test_abs() {
266266
assert_eq!(abs_int(-5), 5);
267267
assert_eq!(abs_int(5), 5);
268-
assert!((abs_float(-3.14) - 3.14).abs() < f64::EPSILON);
268+
assert!((abs_float(-2.5) - 2.5).abs() < f64::EPSILON);
269269
}
270270

271271
#[test]

crates/my-lang/lib/common/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ mod tests {
297297
#[test]
298298
fn test_parse() {
299299
assert_eq!(parse_int("42"), Some(42));
300-
assert_eq!(parse_float("3.14"), Some(3.14));
300+
assert_eq!(parse_float("2.5"), Some(2.5));
301301
}
302302

303303
#[test]

crates/my-lang/lib/common/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ mod tests {
294294

295295
#[test]
296296
fn test_float_conversions() {
297-
assert_eq!(str_to_float("3.14"), Some(3.14));
297+
assert_eq!(str_to_float("2.5"), Some(2.5));
298298
assert_eq!(int_to_float(42), 42.0);
299299
}
300300

301301
#[test]
302302
fn test_str_conversions() {
303303
assert_eq!(int_to_str(42), "42");
304-
assert_eq!(float_to_str(3.14), "3.14");
304+
assert_eq!(float_to_str(2.5), "2.5");
305305
assert_eq!(bool_to_str(true), "true");
306306
}
307307

0 commit comments

Comments
 (0)