1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::models::Number;
cfg_select! {
feature = "decimal" => {
/// Convert an `f64` literal to [`Number`] for use in test assertions.
///
/// When the `decimal` feature is on the value is converted via
/// `Decimal::from_f64`, which mirrors the `serde-with-float`
/// deserialization path so assertions stay consistent.
pub(crate) fn n(v: f64) -> Number {
use rust_decimal::prelude::FromPrimitive;
rust_decimal::Decimal::from_f64(v).expect("f64 -> Decimal conversion failed in test")
}
}
_ => {
/// Convert an `f64` literal to [`Number`] for use in test assertions.
///
/// When the `decimal` feature is off this is a no-op; when it is on the
/// value is converted via `Decimal::from_f64`, which mirrors the
/// `serde-with-float` deserialization path so assertions stay consistent.
pub(crate) fn n(v: f64) -> Number {
v
}
}
}
/// Load a golden JSON fixture file from `tests/fixtures/`.
///
/// Panics if the file doesn't exist or can't be read.
pub(crate) fn fixture(name: &str) -> String {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("fixtures")
.join(name);
std::fs::read_to_string(path)
.unwrap_or_else(|err| panic!("failed to load fixture {name}: {err}"))
}