use zdc_bench::{benchmark_row, emitted_row, try_compile, BENCHMARK_JS, ROW_ZD};
#[test]
fn the_benchmark_row_is_the_compilers_own_emission() {
let emitted = emitted_row(&zdc_bench::compile("crates/zdc-bench/bench/row.zd").client_js);
let benchmark = benchmark_row(BENCHMARK_JS);
assert_eq!(
benchmark.template, emitted.template,
"the markup the benchmark clones per row is no longer the markup the compiler emits \
for bench/row.zd. Update `ROW_HTML` in js/benchmark.js — and check whether the \
numbers in BENCHMARKS.md still describe the same row."
);
assert_eq!(
benchmark.walk, emitted.walk,
"the walk to the row's holes no longer matches the emitter's"
);
assert_eq!(
benchmark.bindings, emitted.bindings,
"the bindings attached to the row no longer match the emitter's, so the benchmark is \
measuring a different number of effects than the compiler would create"
);
assert_eq!(emitted.walk.len(), 4, "{:?}", emitted.walk);
assert_eq!(emitted.bindings.len(), 5, "{:?}", emitted.bindings);
assert!(emitted.template.starts_with("<div class=\"zd-row\">"));
}
#[test]
fn the_row_source_compiles_without_unchecked() {
let bundle = try_compile(ROW_ZD, "bench/row.zd").expect("bench/row.zd compiles");
assert!(bundle.client_js.contains("template("));
assert!(bundle.styles_css.contains(".zd-row"));
}
#[test]
fn the_workloads_list_is_expressible() {
const LIST: &str = "state rows is client List of Text starting empty\n\
\n\
view\n \
Column\n \
each row in rows\n \
Text row\n";
let bundle = try_compile(LIST, "list.zd").unwrap_or_else(|errors| {
panic!(
"a list in the view no longer compiles:\n{}",
errors.join("\n")
)
});
assert!(
bundle.client_js.contains("eachInto"),
"`each` compiled without reaching the runtime's reconciler:\n{}",
bundle.client_js
);
}
#[test]
fn a_list_literal_parses() {
let source = "state rows is client List of Text starting [\"a\", \"b\"]\n";
let program = zdc_parser::parse(source).unwrap_or_else(|error| {
panic!("a list literal no longer parses: {}", error.message);
});
let [zdc_ast::Decl::State(state)] = program.decls.as_slice() else {
panic!("expected one state declaration, got {:?}", program.decls);
};
let zdc_ast::Init::Starting(zdc_ast::Expr::List { items, .. }) = &state.init else {
panic!("expected `starting` a list literal, got {:?}", state.init);
};
assert_eq!(items.len(), 2, "{items:?}");
}