2018-09-30 14:50:46 +00:00
|
|
|
use crate::implementation::{TestContext, TestContextImpl};
|
2018-10-05 10:58:38 +00:00
|
|
|
use salsa::Database;
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 14:35:50 +00:00
|
|
|
salsa::query_group! {
|
2018-10-02 00:42:41 +00:00
|
|
|
crate trait MemoizedInputsContext: TestContext {
|
2018-10-05 09:28:51 +00:00
|
|
|
fn max(key: ()) -> usize {
|
|
|
|
type Max;
|
|
|
|
}
|
|
|
|
fn input1(key: ()) -> usize {
|
|
|
|
type Input1;
|
2018-10-05 09:51:18 +00:00
|
|
|
storage input;
|
2018-10-05 09:28:51 +00:00
|
|
|
}
|
|
|
|
fn input2(key: ()) -> usize {
|
|
|
|
type Input2;
|
2018-10-05 09:51:18 +00:00
|
|
|
storage input;
|
2018-10-05 09:28:51 +00:00
|
|
|
}
|
2018-09-30 14:50:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 14:30:17 +00:00
|
|
|
fn max(db: &impl MemoizedInputsContext, (): ()) -> usize {
|
|
|
|
db.log().add("Max invoked");
|
|
|
|
std::cmp::max(db.input1(()), db.input2(()))
|
2018-09-30 14:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn revalidate() {
|
2018-10-05 09:28:51 +00:00
|
|
|
let db = &TestContextImpl::default();
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 09:28:51 +00:00
|
|
|
let v = db.max(());
|
2018-09-30 14:50:46 +00:00
|
|
|
assert_eq!(v, 0);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&["Max invoked"]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 09:28:51 +00:00
|
|
|
let v = db.max(());
|
2018-09-30 14:50:46 +00:00
|
|
|
assert_eq!(v, 0);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 10:58:38 +00:00
|
|
|
db.query(Input1).set((), 44);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 09:28:51 +00:00
|
|
|
let v = db.max(());
|
2018-09-30 14:50:46 +00:00
|
|
|
assert_eq!(v, 44);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&["Max invoked"]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 09:28:51 +00:00
|
|
|
let v = db.max(());
|
2018-09-30 14:50:46 +00:00
|
|
|
assert_eq!(v, 44);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 10:58:38 +00:00
|
|
|
db.query(Input1).set((), 44);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-10-05 10:58:38 +00:00
|
|
|
db.query(Input2).set((), 66);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-10-05 10:58:38 +00:00
|
|
|
db.query(Input1).set((), 64);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 09:28:51 +00:00
|
|
|
let v = db.max(());
|
2018-09-30 14:50:46 +00:00
|
|
|
assert_eq!(v, 66);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&["Max invoked"]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-05 09:28:51 +00:00
|
|
|
let v = db.max(());
|
2018-09-30 14:50:46 +00:00
|
|
|
assert_eq!(v, 66);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-09-30 14:50:46 +00:00
|
|
|
}
|