mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 05:07:27 +00:00
add a test
This commit is contained in:
parent
1ae6a7bbc5
commit
a1db7d4e84
1 changed files with 48 additions and 0 deletions
48
salsa-2022-tests/tests/tracked_fn_read_own_specify.rs
Normal file
48
salsa-2022-tests/tests/tracked_fn_read_own_specify.rs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#![allow(warnings)]
|
||||||
|
|
||||||
|
#[salsa::jar(db = Db)]
|
||||||
|
struct Jar(MyInput, MyTracked, tracked_fn, tracked_fn_extra);
|
||||||
|
|
||||||
|
trait Db: salsa::DbWithJar<Jar> {}
|
||||||
|
|
||||||
|
#[salsa::input(jar = Jar)]
|
||||||
|
struct MyInput {
|
||||||
|
field: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked(jar = Jar)]
|
||||||
|
struct MyTracked {
|
||||||
|
field: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked(jar = Jar)]
|
||||||
|
fn tracked_fn(db: &dyn Db, input: MyInput) -> u32 {
|
||||||
|
let t = MyTracked::new(db, input.field(db) * 2);
|
||||||
|
tracked_fn_extra::specify(db, t, 2222);
|
||||||
|
tracked_fn_extra(db, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked(jar = Jar, specify)]
|
||||||
|
fn tracked_fn_extra(_db: &dyn Db, _input: MyTracked) -> u32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::db(Jar)]
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Database {
|
||||||
|
storage: salsa::Storage<Self>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl salsa::Database for Database {}
|
||||||
|
|
||||||
|
impl Db for Database {}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn execute() {
|
||||||
|
let mut db = Database::default();
|
||||||
|
let input = MyInput::new(&mut db, 22);
|
||||||
|
assert_eq!(tracked_fn(&db, input), 2222);
|
||||||
|
|
||||||
|
let input2 = MyInput::new(&mut db, 44);
|
||||||
|
assert_eq!(tracked_fn(&db, input), 2222);
|
||||||
|
}
|
Loading…
Reference in a new issue