salsa/tests/tracked_with_struct_db.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

//! Test that a setting a field on a `#[salsa::input]`
//! overwrites and returns the old value.
use salsa::{Database, DatabaseImpl};
use test_log::test;
#[salsa::input]
struct MyInput {
field: String,
}
#[salsa::tracked]
struct MyTracked<'db> {
data: MyInput,
next: MyList<'db>,
}
2024-07-17 12:42:06 +00:00
#[derive(PartialEq, Eq, Clone, Debug, salsa::Update)]
enum MyList<'db> {
None,
Next(MyTracked<'db>),
}
#[salsa::tracked]
fn create_tracked_list(db: &dyn Database, input: MyInput) -> MyTracked<'_> {
let t0 = MyTracked::new(db, input, MyList::None);
let t1 = MyTracked::new(db, input, MyList::Next(t0));
t1
}
#[test]
fn execute() {
DatabaseImpl::new().attach(|db| {
2024-07-17 12:45:49 +00:00
let input = MyInput::new(db, "foo".to_string());
let t0: MyTracked = create_tracked_list(db, input);
let t1 = create_tracked_list(db, input);
expect_test::expect![[r#"
MyTracked {
2024-08-14 05:07:28 +00:00
[salsa id]: Id(401),
2024-07-17 12:45:49 +00:00
data: MyInput {
[salsa id]: Id(0),
2024-07-17 12:45:49 +00:00
field: "foo",
},
next: Next(
MyTracked {
2024-08-14 05:07:28 +00:00
[salsa id]: Id(400),
2024-07-17 12:45:49 +00:00
data: MyInput {
[salsa id]: Id(0),
2024-07-17 12:45:49 +00:00
field: "foo",
},
next: None,
2024-05-21 09:57:04 +00:00
},
2024-07-17 12:45:49 +00:00
),
}
"#]]
.assert_debug_eq(&t0);
assert_eq!(t0, t1);
})
}