Skip to content

Commit 52d9ee5

Browse files
refactor: simplify float precision test assertion
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent dc50815 commit 52d9ee5

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

crates/rolldown_common/src/ecmascript/json_to_program.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ mod tests {
171171
assert_snapshot!(to_code(&serde_json::from_str::<Value>(r#"{"a": 1, "a": 2}"#).unwrap()), @r#"({ "a": 2 });"#);
172172
}
173173

174-
/// Test that 17-significant-digit floats roundtrip correctly through JSON→AST→codegen.
175-
/// The codegen may use a shorter representation (e.g. 15 digits) if it roundtrips to the same f64.
176174
/// Regression test for https://github.com/vitejs/vite/issues/21982
177175
#[test]
178176
fn test_float_17_significant_digits() {
@@ -186,16 +184,9 @@ mod tests {
186184
r"[114.35143799257997, 406.31486713248995, 163.41498018498498, 364.09498724900986]",
187185
)
188186
.unwrap();
189-
let code = to_code(&json);
190-
191-
// Extract numbers from generated code and verify they parse to the same f64 values
192-
for expected in &inputs {
193-
let found = code
194-
.split(|c: char| !c.is_ascii_digit() && c != '.' && c != '-')
195-
.filter_map(|s| s.parse::<f64>().ok())
196-
.any(|v| v.to_bits() == expected.to_bits());
197-
assert!(found, "f64 value {expected} not found (same bits) in output: {code}");
198-
}
187+
let code: String = to_code(&json).chars().filter(|c| !c.is_whitespace()).collect();
188+
let expected = format!("[{}];", inputs.map(|v| v.to_string()).join(","));
189+
assert_eq!(code, expected);
199190
}
200191

201192
#[test]

0 commit comments

Comments
 (0)