salsa/tests/tracked_method.rs

43 lines
967 B
Rust
Raw Normal View History

//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
#![allow(warnings)]
2022-09-03 14:44:56 +00:00
trait TrackedTrait {
2024-07-17 11:49:46 +00:00
fn tracked_trait_fn(self, db: &dyn salsa::Database) -> u32;
2022-09-03 14:44:56 +00:00
}
#[salsa::input]
struct MyInput {
field: u32,
}
#[salsa::tracked]
impl MyInput {
#[salsa::tracked]
2024-07-18 09:59:43 +00:00
fn tracked_fn(self, db: &dyn salsa::Database) -> u32 {
self.field(db) * 2
}
#[salsa::tracked(return_ref)]
2024-07-18 09:59:43 +00:00
fn tracked_fn_ref(self, db: &dyn salsa::Database) -> u32 {
self.field(db) * 3
}
}
2022-09-03 14:44:56 +00:00
#[salsa::tracked]
impl TrackedTrait for MyInput {
#[salsa::tracked]
2024-07-18 09:59:43 +00:00
fn tracked_trait_fn(self, db: &dyn salsa::Database) -> u32 {
2022-09-03 14:44:56 +00:00
self.field(db) * 4
}
}
#[test]
fn execute() {
let mut db = salsa::DatabaseImpl::new();
let object = MyInput::new(&mut db, 22);
2024-07-18 09:59:43 +00:00
// assert_eq!(object.tracked_fn(&db), 44);
// assert_eq!(*object.tracked_fn_ref(&db), 66);
2022-09-03 14:44:56 +00:00
assert_eq!(object.tracked_trait_fn(&db), 88);
}