mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 16:35:21 +00:00
add some simple tests using is_constant
This commit is contained in:
parent
16d151e4c8
commit
efa8b0f307
2 changed files with 45 additions and 12 deletions
|
@ -1,30 +1,32 @@
|
||||||
use crate::implementation::{TestContext, TestContextImpl};
|
use crate::implementation::{TestContext, TestContextImpl};
|
||||||
|
use salsa::debug::DebugQueryTable;
|
||||||
use salsa::Database;
|
use salsa::Database;
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
pub(crate) trait ConstantsDatabase: TestContext {
|
pub(crate) trait ConstantsDatabase: TestContext {
|
||||||
fn constants_input(key: usize) -> usize {
|
fn constants_input(key: char) -> usize {
|
||||||
type ConstantsInput;
|
type ConstantsInput;
|
||||||
storage input;
|
storage input;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constants_derived(key: usize) -> usize {
|
fn constants_add(keys: (char, char)) -> usize {
|
||||||
type ConstantsDerived;
|
type ConstantsAdd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constants_derived(db: &impl ConstantsDatabase, key: usize) -> usize {
|
fn constants_add(db: &impl ConstantsDatabase, (key1, key2): (char, char)) -> usize {
|
||||||
db.log().add(format!("constants_derived({}) invoked", key));
|
db.log()
|
||||||
db.constants_input(key) * 2
|
.add(format!("constants_derived({}, {}) invoked", key1, key2));
|
||||||
|
db.constants_input(key1) + db.constants_input(key2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn invalidate_constant() {
|
fn invalidate_constant() {
|
||||||
let db = &TestContextImpl::default();
|
let db = &TestContextImpl::default();
|
||||||
db.query(ConstantsInput).set_constant(22, 44);
|
db.query(ConstantsInput).set_constant('a', 44);
|
||||||
db.query(ConstantsInput).set_constant(22, 66);
|
db.query(ConstantsInput).set_constant('a', 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -33,11 +35,42 @@ fn invalidate_constant_1() {
|
||||||
let db = &TestContextImpl::default();
|
let db = &TestContextImpl::default();
|
||||||
|
|
||||||
// Not constant:
|
// Not constant:
|
||||||
db.query(ConstantsInput).set(22, 44);
|
db.query(ConstantsInput).set('a', 44);
|
||||||
|
|
||||||
// Becomes constant:
|
// Becomes constant:
|
||||||
db.query(ConstantsInput).set_constant(22, 44);
|
db.query(ConstantsInput).set_constant('a', 44);
|
||||||
|
|
||||||
// Invalidates:
|
// Invalidates:
|
||||||
db.query(ConstantsInput).set_constant(22, 66);
|
db.query(ConstantsInput).set_constant('a', 66);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn not_constant() {
|
||||||
|
let db = &TestContextImpl::default();
|
||||||
|
|
||||||
|
db.query(ConstantsInput).set('a', 22);
|
||||||
|
db.query(ConstantsInput).set('b', 44);
|
||||||
|
assert_eq!(db.constants_add(('a', 'b')), 66);
|
||||||
|
assert!(!db.query(ConstantsAdd).is_constant(('a', 'b')));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_constant() {
|
||||||
|
let db = &TestContextImpl::default();
|
||||||
|
|
||||||
|
db.query(ConstantsInput).set_constant('a', 22);
|
||||||
|
db.query(ConstantsInput).set_constant('b', 44);
|
||||||
|
assert_eq!(db.constants_add(('a', 'b')), 66);
|
||||||
|
assert!(db.query(ConstantsAdd).is_constant(('a', 'b')));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mixed_constant() {
|
||||||
|
let db = &TestContextImpl::default();
|
||||||
|
|
||||||
|
db.query(ConstantsInput).set_constant('a', 22);
|
||||||
|
db.query(ConstantsInput).set('b', 44);
|
||||||
|
assert_eq!(db.constants_add(('a', 'b')), 66);
|
||||||
|
assert!(!db.query(ConstantsAdd).is_constant(('a', 'b')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ salsa::database_storage! {
|
||||||
pub(crate) struct TestContextImplStorage for TestContextImpl {
|
pub(crate) struct TestContextImplStorage for TestContextImpl {
|
||||||
impl constants::ConstantsDatabase {
|
impl constants::ConstantsDatabase {
|
||||||
fn constants_input() for constants::ConstantsInput;
|
fn constants_input() for constants::ConstantsInput;
|
||||||
fn constants_derived() for constants::ConstantsDerived;
|
fn constants_derived() for constants::ConstantsAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl memoized_dep_inputs::MemoizedDepInputsContext {
|
impl memoized_dep_inputs::MemoizedDepInputsContext {
|
||||||
|
|
Loading…
Reference in a new issue