Skip to content

Commit

Permalink
test: implement tests for overwriting values with overwrite_left_with…
Browse files Browse the repository at this point in the history
…_right

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Feb 22, 2024
1 parent 3c71a74 commit a239a46
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/core/src/domain/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct Activity {
// TODO: Reconsider when we implement the project management part
// category: Category,
#[builder(default)]
#[getset(get = "pub", get_mut = "pub")]
#[serde(skip_serializing_if = "Option::is_none")]
category: Option<String>,

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ pub use crate::{
ActivityQuerying, ActivityReadOps, ActivityStateManagement, ActivityStorage,
ActivityWriteOps, SyncStorage,
},
util::overwrite,
util::overwrite_left_with_right,
};
35 changes: 34 additions & 1 deletion crates/core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@
///
/// * `left` - The left value
/// * `right` - The right value
pub fn overwrite<T>(left: &mut T, right: T) {
pub fn overwrite_left_with_right<T>(left: &mut T, right: T) {
*left = right;
}

#[cfg(test)]
mod tests {

use crate::Activity;

use super::*;

#[test]
fn test_overwrite_i32_passes() {
let mut left = 1;
let right = 2;
overwrite_left_with_right(&mut left, right);
assert_eq!(left, 2);
}

#[test]
fn test_overwrite_string_passes() {
let mut left = String::from("left");
let right = String::from("right");
overwrite_left_with_right(&mut left, right);
assert_eq!(left, "right");
}

#[test]
fn test_overwrite_activity_passes() {
let mut left = Activity::default();
let mut right = Activity::default();
_ = right.category_mut().replace("right".to_string());
overwrite_left_with_right(&mut left, right);
assert_eq!(left.category(), &Some("right".to_string()));
}
}

0 comments on commit a239a46

Please sign in to comment.