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
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
#[salsa::query_group]
|
|
|
|
pub(crate) trait MemoizedInputsContext: TestContext {
|
|
|
|
fn max(&self) -> usize;
|
|
|
|
#[salsa::input]
|
|
|
|
fn input1(&self) -> usize;
|
|
|
|
#[salsa::input]
|
|
|
|
fn input2(&self) -> usize;
|
2018-09-30 14:50:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 01:26:48 +00:00
|
|
|
fn max(db: &impl MemoizedInputsContext) -> usize {
|
2018-10-05 14:30:17 +00:00
|
|
|
db.log().add("Max invoked");
|
2018-10-19 01:26:48 +00:00
|
|
|
std::cmp::max(db.input1(), db.input2())
|
2018-09-30 14:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn revalidate() {
|
2018-11-01 08:30:54 +00:00
|
|
|
let db = &mut TestContextImpl::default();
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input1Query).set((), 0);
|
|
|
|
db.query_mut(Input2Query).set((), 0);
|
2018-10-30 16:59:33 +00:00
|
|
|
|
2018-10-19 01:26:48 +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-19 01:26:48 +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
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input1Query).set((), 44);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-19 01:26:48 +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-19 01:26:48 +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
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input1Query).set((), 44);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input2Query).set((), 66);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input1Query).set((), 64);
|
2018-10-05 09:28:51 +00:00
|
|
|
db.assert_log(&[]);
|
2018-09-30 14:50:46 +00:00
|
|
|
|
2018-10-19 01:26:48 +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-19 01:26:48 +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
|
|
|
}
|
2018-10-11 08:59:07 +00:00
|
|
|
|
2018-10-30 16:59:33 +00:00
|
|
|
/// Test that invoking `set` on an input with the same value still
|
|
|
|
/// triggers a new revision.
|
2018-10-11 08:59:07 +00:00
|
|
|
#[test]
|
|
|
|
fn set_after_no_change() {
|
2018-11-01 08:30:54 +00:00
|
|
|
let db = &mut TestContextImpl::default();
|
2018-10-11 08:59:07 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input2Query).set((), 0);
|
2018-10-30 16:59:33 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input1Query).set((), 44);
|
2018-10-19 01:26:48 +00:00
|
|
|
let v = db.max();
|
2018-10-11 08:59:07 +00:00
|
|
|
assert_eq!(v, 44);
|
|
|
|
db.assert_log(&["Max invoked"]);
|
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(Input1Query).set((), 44);
|
2018-10-19 01:26:48 +00:00
|
|
|
let v = db.max();
|
2018-10-11 08:59:07 +00:00
|
|
|
assert_eq!(v, 44);
|
2018-10-30 16:59:33 +00:00
|
|
|
db.assert_log(&["Max invoked"]);
|
2018-10-11 08:59:07 +00:00
|
|
|
}
|