salsa/tests/gc/db.rs
Fabian Schuiki 93c30a953d make query_group macro procedural
Switch to a procedural implementation of the `query_group!` macro,
residing in the `components/salsa_macros` subcrate.

Allow the user to override the invoked function via `salsa::invoke(...)`
and the name of the generated query type via `salsa::query_type(...)`.

In all tests, replace the `salsa::query_group! { ... }` invocations with
the new attribute-style `#[salsa::query_group]` macro, and change them
to the new naming scheme for query types (`...Query`).

Update README, examples, and documentation.
2019-01-17 07:24:18 +01:00

60 lines
1.5 KiB
Rust

use crate::group;
use crate::log::{HasLog, Log};
#[derive(Default)]
pub struct DatabaseImpl {
runtime: salsa::Runtime<DatabaseImpl>,
log: Log,
}
impl salsa::Database for DatabaseImpl {
fn salsa_runtime(&self) -> &salsa::Runtime<DatabaseImpl> {
&self.runtime
}
}
salsa::database_storage! {
pub struct DatabaseImplStorage for DatabaseImpl {
impl group::GcDatabase {
fn min() for group::MinQuery;
fn max() for group::MaxQuery;
fn use_triangular() for group::UseTriangularQuery;
fn fibonacci() for group::FibonacciQuery;
fn triangular() for group::TriangularQuery;
fn compute() for group::ComputeQuery;
fn compute_all() for group::ComputeAllQuery;
}
}
}
impl DatabaseImpl {
pub(crate) fn clear_log(&self) {
self.log().take();
}
pub(crate) fn assert_log(&self, expected_log: &[&str]) {
let expected_text = &format!("{:#?}", expected_log);
let actual_text = &format!("{:#?}", self.log().take());
if expected_text == actual_text {
return;
}
for diff in diff::lines(expected_text, actual_text) {
match diff {
diff::Result::Left(l) => println!("-{}", l),
diff::Result::Both(l, _) => println!(" {}", l),
diff::Result::Right(r) => println!("+{}", r),
}
}
panic!("incorrect log results");
}
}
impl HasLog for DatabaseImpl {
fn log(&self) -> &Log {
&self.log
}
}