use zenith_cli::commands::render::to_png_with_dir;
use zenith_cli::config::CliPolicyFlags;
const WITHOUT_ID: &str = r##"zenith version=1 {
project id="proj.hist" name="History Test"
tokens format="zenith-token-v1" {
token id="color.bg" type="color" value="#f8fafc"
}
styles {
}
document id="doc.hist" title="History Test" {
page id="page.one" w=(px)480 h=(px)160 {
rect id="rect.bg" x=(px)0 y=(px)0 w=(px)480 h=(px)160 fill=(token)"color.bg"
}
}
}
"##;
fn with_id() -> String {
let out = WITHOUT_ID.replace(
"zenith version=1 {",
r#"zenith version=1 doc-id="01ARZ3NDEKTSV4RRFFQ69G5FAV" {"#,
);
assert_ne!(
out, WITHOUT_ID,
"the doc-id substitution must actually change the source"
);
out
}
#[test]
fn doc_id_is_render_ignored() {
let with = with_id();
let png_without = to_png_with_dir(WITHOUT_ID, None, 1, false, &CliPolicyFlags::default(), None)
.unwrap_or_else(|e| {
panic!(
"render WITHOUT doc-id failed (exit {}): {}",
e.exit_code, e.message
)
})
.png;
let png_with = to_png_with_dir(&with, None, 1, false, &CliPolicyFlags::default(), None)
.unwrap_or_else(|e| {
panic!(
"render WITH doc-id failed (exit {}): {}",
e.exit_code, e.message
)
})
.png;
assert!(!png_without.is_empty(), "render output must not be empty");
assert_eq!(
png_with, png_without,
"doc-id must be render-ignored: WITH and WITHOUT doc-id must render byte-identical PNGs"
);
}
#[test]
fn render_with_doc_id_is_deterministic() {
let with = with_id();
let first = to_png_with_dir(&with, None, 1, false, &CliPolicyFlags::default(), None)
.unwrap_or_else(|e| panic!("first render failed (exit {}): {}", e.exit_code, e.message))
.png;
let second = to_png_with_dir(&with, None, 1, false, &CliPolicyFlags::default(), None)
.unwrap_or_else(|e| panic!("second render failed (exit {}): {}", e.exit_code, e.message))
.png;
assert_eq!(
first, second,
"two renders of the WITH-doc-id fixture must produce identical bytes"
);
}