salsa/tests/input_setter_preserves_durability.rs
Lukas Wirth a89e3d2357
chore: Normalize imports style (#779)
* Default impl some ingredient functions

* chore: Normalize imports style

Effectively reformatted everything with
```toml
imports_granularity = "Module"
group_imports = "StdExternalCrate"
reorder_imports = true
```
2025-03-28 05:11:40 +00:00

33 lines
821 B
Rust

use salsa::plumbing::ZalsaDatabase;
use salsa::{Durability, Setter};
use test_log::test;
#[salsa::input]
struct MyInput {
required_field: bool,
#[default]
optional_field: usize,
}
#[test]
fn execute() {
let mut db = salsa::DatabaseImpl::new();
let input = MyInput::builder(true)
.required_field_durability(Durability::HIGH)
.new(&db);
// Change the field value. It should preserve high durability.
input.set_required_field(&mut db).to(false);
let last_high_revision = db.zalsa().last_changed_revision(Durability::HIGH);
// Changing the value again should **again** dump the high durability revision.
input.set_required_field(&mut db).to(false);
assert_ne!(
db.zalsa().last_changed_revision(Durability::HIGH),
last_high_revision
);
}