salsa/tests/storage_varieties/tests.rs
Aleksey Kladov 46c55a1e5b Disable underscore_imports
Builds with beta now!
2018-10-09 22:40:03 +03:00

48 lines
1.2 KiB
Rust

#![cfg(test)]
use crate::implementation::DatabaseImpl;
use crate::queries::Database;
use salsa::Database as _Database;
#[test]
fn memoized_twice() {
let db = DatabaseImpl::default();
let v1 = db.memoized(());
let v2 = db.memoized(());
assert_eq!(v1, v2);
}
#[test]
fn volatile_twice() {
let db = DatabaseImpl::default();
let v1 = db.volatile(());
let v2 = db.volatile(()); // volatiles are cached, so 2nd read returns the same
assert_eq!(v1, v2);
db.salsa_runtime().next_revision(); // clears volatile caches
let v3 = db.volatile(()); // will re-increment the counter
let v4 = db.volatile(()); // second call will be cached
assert_eq!(v1 + 1, v3);
assert_eq!(v3, v4);
}
#[test]
fn intermingled() {
let db = DatabaseImpl::default();
let v1 = db.volatile(());
let v2 = db.memoized(());
let v3 = db.volatile(()); // cached
let v4 = db.memoized(()); // cached
assert_eq!(v1, v2);
assert_eq!(v1, v3);
assert_eq!(v2, v4);
db.salsa_runtime().next_revision(); // clears volatile caches
let v5 = db.memoized(()); // re-executes volatile, caches new result
let v6 = db.memoized(()); // re-use cached result
assert_eq!(v4 + 1, v5);
assert_eq!(v5, v6);
}