-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from MichaReiser/setter-preserve-durability
Preserve durability when setting a new input-value
- Loading branch information
Showing
3 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use test_log::test; | ||
|
||
use salsa::plumbing::ZalsaDatabase; | ||
use salsa::{Durability, Setter}; | ||
|
||
#[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 | ||
); | ||
} |