add some tests for constants (check for invalidation)

This commit is contained in:
Niko Matsakis 2018-10-09 20:35:57 -04:00
parent 42b88fe7e6
commit 15faf43071
3 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,43 @@
use crate::implementation::{TestContext, TestContextImpl};
use salsa::Database;
salsa::query_group! {
pub(crate) trait ConstantsDatabase: TestContext {
fn constants_input(key: usize) -> usize {
type ConstantsInput;
storage input;
}
fn constants_derived(key: usize) -> usize {
type ConstantsDerived;
}
}
}
fn constants_derived(db: &impl ConstantsDatabase, key: usize) -> usize {
db.log().add(format!("constants_derived({}) invoked", key));
db.constants_input(key) * 2
}
#[test]
#[should_panic]
fn invalidate_constant() {
let db = &TestContextImpl::default();
db.query(ConstantsInput).set_constant(22, 44);
db.query(ConstantsInput).set_constant(22, 66);
}
#[test]
#[should_panic]
fn invalidate_constant_1() {
let db = &TestContextImpl::default();
// Not constant:
db.query(ConstantsInput).set(22, 44);
// Becomes constant:
db.query(ConstantsInput).set_constant(22, 44);
// Invalidates:
db.query(ConstantsInput).set_constant(22, 66);
}

View file

@ -1,3 +1,4 @@
use crate::constants;
use crate::counter::Counter;
use crate::log::Log;
use crate::memoized_dep_inputs;
@ -43,6 +44,11 @@ impl TestContextImpl {
salsa::database_storage! {
pub(crate) struct TestContextImplStorage for TestContextImpl {
impl constants::ConstantsDatabase {
fn constants_input() for constants::ConstantsInput;
fn constants_derived() for constants::ConstantsDerived;
}
impl memoized_dep_inputs::MemoizedDepInputsContext {
fn dep_memoized2() for memoized_dep_inputs::Memoized2;
fn dep_memoized1() for memoized_dep_inputs::Memoized1;

View file

@ -1,3 +1,4 @@
mod constants;
mod counter;
mod implementation;
mod log;