Files
faunosteo/crates/core/tests/fixtures_round_trip.rs
T

40 lines
1.4 KiB
Rust

//! R0 proof (half of it): the JavaScript pretty form is idempotent on the real documents and
//! prints no integer-valued float with a fraction. The other half, byte equality against
//! `JSON.stringify(JSON.parse(text), null, 2)`, runs in `packages/core-wasm/tests` on the
//! same files through the wasm build.
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
use faunosteo_core::json::pretty_js_round_trip;
fn fixture(relative: &str) -> String {
let path = format!("{}/../../{relative}", env!("CARGO_MANIFEST_DIR"));
std::fs::read_to_string(&path).unwrap_or_else(|error| panic!("{path}: {error}"))
}
fn assert_round_trip(relative: &str) -> String {
let text = fixture(relative);
let once = pretty_js_round_trip(&text).expect("first pass");
let twice = pretty_js_round_trip(&once).expect("second pass");
assert_eq!(
once, twice,
"{relative}: the pretty form must be a fixed point"
);
assert!(
!once.contains(".0,") && !once.contains(".0\n"),
"{relative}: a float printed as x.0"
);
once
}
#[test]
fn demo_report_v3_round_trips() {
let text = assert_round_trip("apps/app/tests/fixtures/report-v3.demo.json");
assert!(text.starts_with("{\n \"version\": 3,\n"));
}
#[test]
fn equine_draft_document_round_trips() {
let text = assert_round_trip("supabase/seed/anatomical-sheets/equine/draft/document.json");
assert!(text.contains("\"schema_version\": 2"));
}