salsa/tests/accumulate-custom-debug.rs
Lukas Wirth 679d82c4e7
Some checks are pending
Book / Book (push) Waiting to run
Book / Deploy (push) Blocked by required conditions
Release-plz / Release-plz PR (push) Waiting to run
Release-plz / Release-plz release (push) Waiting to run
Test / Test (push) Waiting to run
Test / Miri (push) Waiting to run
Test / Shuttle (push) Waiting to run
Test / Benchmarks (push) Waiting to run
Gate accumulator feature behind a feature flag (#946)
2025-08-02 08:41:17 +00:00

47 lines
1 KiB
Rust

#![cfg(all(feature = "inventory", feature = "accumulator"))]
mod common;
use expect_test::expect;
use salsa::{Accumulator, Database};
use test_log::test;
#[salsa::input(debug)]
struct MyInput {
count: u32,
}
#[salsa::accumulator]
struct Log(String);
impl std::fmt::Debug for Log {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("CustomLog").field(&self.0).finish()
}
}
#[salsa::tracked]
fn push_logs(db: &dyn salsa::Database, input: MyInput) {
for i in 0..input.count(db) {
Log(format!("#{i}")).accumulate(db);
}
}
#[test]
fn accumulate_custom_debug() {
salsa::DatabaseImpl::new().attach(|db| {
let input = MyInput::new(db, 2);
let logs = push_logs::accumulated::<Log>(db, input);
expect![[r##"
[
CustomLog(
"#0",
),
CustomLog(
"#1",
),
]
"##]]
.assert_debug_eq(&logs);
})
}