rust-analyzer/crates/salsa/tests/incremental/implementation.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.4 KiB
Rust
Raw Normal View History

2024-02-07 15:29:46 +00:00
use crate::constants;
use crate::counter::Counter;
use crate::log::Log;
use crate::memoized_dep_inputs;
use crate::memoized_inputs;
use crate::memoized_volatile;
pub(crate) trait TestContext: salsa::Database {
fn clock(&self) -> &Counter;
fn log(&self) -> &Log;
}
#[salsa::database(
constants::Constants,
memoized_dep_inputs::MemoizedDepInputs,
memoized_inputs::MemoizedInputs,
memoized_volatile::MemoizedVolatile
)]
#[derive(Default)]
pub(crate) struct TestContextImpl {
storage: salsa::Storage<TestContextImpl>,
clock: Counter,
log: Log,
}
impl TestContextImpl {
#[track_caller]
pub(crate) fn assert_log(&self, expected_log: &[&str]) {
2024-05-30 23:18:49 +00:00
let expected_text = &format!("{expected_log:#?}");
2024-02-07 15:29:46 +00:00
let actual_text = &format!("{:#?}", self.log().take());
if expected_text == actual_text {
return;
}
2024-02-07 15:53:27 +00:00
#[allow(clippy::print_stdout)]
2024-02-07 15:34:21 +00:00
for diff in dissimilar::diff(expected_text, actual_text) {
2024-02-07 15:29:46 +00:00
match diff {
2024-05-30 23:18:49 +00:00
dissimilar::Chunk::Delete(l) => println!("-{l}"),
dissimilar::Chunk::Equal(l) => println!(" {l}"),
dissimilar::Chunk::Insert(r) => println!("+{r}"),
2024-02-07 15:29:46 +00:00
}
}
panic!("incorrect log results");
}
}
impl TestContext for TestContextImpl {
fn clock(&self) -> &Counter {
&self.clock
}
fn log(&self) -> &Log {
&self.log
}
}
impl salsa::Database for TestContextImpl {}