mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
update a test
This commit is contained in:
parent
a2be847e1a
commit
559c02ba80
1 changed files with 25 additions and 5 deletions
|
@ -1,9 +1,11 @@
|
|||
#![allow(warnings)]
|
||||
use expect_test::expect;
|
||||
use salsa::{Database as SalsaDatabase, DebugWithDb};
|
||||
use salsa_2022_tests::{HasLogger, Logger};
|
||||
|
||||
#[salsa::jar(db = Db)]
|
||||
struct Jar(MyInput, MyTracked, tracked_fn, tracked_fn_extra);
|
||||
|
||||
trait Db: salsa::DbWithJar<Jar> {}
|
||||
trait Db: salsa::DbWithJar<Jar> + HasLogger {}
|
||||
|
||||
#[salsa::input(jar = Jar)]
|
||||
struct MyInput {
|
||||
|
@ -17,13 +19,15 @@ struct MyTracked {
|
|||
|
||||
#[salsa::tracked(jar = Jar)]
|
||||
fn tracked_fn(db: &dyn Db, input: MyInput) -> u32 {
|
||||
db.push_log(format!("tracked_fn({:?})", input.debug(db)));
|
||||
let t = MyTracked::new(db, input.field(db) * 2);
|
||||
tracked_fn_extra::specify(db, t, 2222);
|
||||
tracked_fn_extra(db, t)
|
||||
}
|
||||
|
||||
#[salsa::tracked(jar = Jar, specify)]
|
||||
fn tracked_fn_extra(_db: &dyn Db, _input: MyTracked) -> u32 {
|
||||
fn tracked_fn_extra(db: &dyn Db, input: MyTracked) -> u32 {
|
||||
db.push_log(format!("tracked_fn_extra({:?})", input.debug(db)));
|
||||
0
|
||||
}
|
||||
|
||||
|
@ -31,18 +35,34 @@ fn tracked_fn_extra(_db: &dyn Db, _input: MyTracked) -> u32 {
|
|||
#[derive(Default)]
|
||||
struct Database {
|
||||
storage: salsa::Storage<Self>,
|
||||
logger: Logger,
|
||||
}
|
||||
|
||||
impl salsa::Database for Database {}
|
||||
|
||||
impl Db for Database {}
|
||||
|
||||
impl HasLogger for Database {
|
||||
fn logger(&self) -> &Logger {
|
||||
&self.logger
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn execute() {
|
||||
let mut db = Database::default();
|
||||
let input = MyInput::new(&mut db, 22);
|
||||
let input = MyInput::new(&db, 22);
|
||||
assert_eq!(tracked_fn(&db, input), 2222);
|
||||
db.assert_logs(expect![[r#"
|
||||
[
|
||||
"tracked_fn(MyInput { [salsa id]: 0 })",
|
||||
]"#]]);
|
||||
|
||||
let input2 = MyInput::new(&mut db, 44);
|
||||
// A "synthetic write" causes the system to act *as though* some
|
||||
// input of durability `durability` has changed.
|
||||
db.synthetic_write(salsa::Durability::LOW);
|
||||
|
||||
// Re-run the query on the original input. Nothing re-executes!
|
||||
assert_eq!(tracked_fn(&db, input), 2222);
|
||||
db.assert_logs(expect!["[]"]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue