2024-05-20 11:28:28 +00:00
|
|
|
//! Test that a setting a field on a `#[salsa::input]`
|
|
|
|
//! overwrites and returns the old value.
|
|
|
|
|
2024-07-17 12:45:49 +00:00
|
|
|
use salsa::Database as _;
|
2024-05-20 11:28:28 +00:00
|
|
|
use test_log::test;
|
|
|
|
|
2024-07-17 12:42:06 +00:00
|
|
|
#[salsa::db]
|
2024-05-20 11:28:28 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
struct Database {
|
|
|
|
storage: salsa::Storage<Self>,
|
|
|
|
}
|
|
|
|
|
2024-07-17 12:42:06 +00:00
|
|
|
#[salsa::db]
|
2024-05-20 11:28:28 +00:00
|
|
|
impl salsa::Database for Database {}
|
|
|
|
|
|
|
|
#[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)]
|
2024-05-20 11:28:28 +00:00
|
|
|
enum MyList<'db> {
|
|
|
|
None,
|
|
|
|
Next(MyTracked<'db>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked]
|
2024-07-19 13:13:48 +00:00
|
|
|
fn create_tracked_list(db: &dyn salsa::Database, input: MyInput) -> MyTracked<'_> {
|
2024-05-20 11:28:28 +00:00
|
|
|
let t0 = MyTracked::new(db, input, MyList::None);
|
|
|
|
let t1 = MyTracked::new(db, input, MyList::Next(t0));
|
|
|
|
t1
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn execute() {
|
2024-07-17 12:45:49 +00:00
|
|
|
Database::default().attach(|db| {
|
|
|
|
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 {
|
|
|
|
[salsa id]: 1,
|
|
|
|
data: MyInput {
|
2024-05-21 09:47:13 +00:00
|
|
|
[salsa id]: 0,
|
2024-07-17 12:45:49 +00:00
|
|
|
field: "foo",
|
|
|
|
},
|
|
|
|
next: Next(
|
|
|
|
MyTracked {
|
2024-05-21 09:57:04 +00:00
|
|
|
[salsa id]: 0,
|
2024-07-17 12:45:49 +00:00
|
|
|
data: MyInput {
|
|
|
|
[salsa id]: 0,
|
|
|
|
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);
|
|
|
|
})
|
2024-05-20 11:28:28 +00:00
|
|
|
}
|