Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ mod tests {

#[test]
fn test_nested() {
#[derive(PartialEq, Debug, Patch, Deserialize)]
#[derive(PartialEq, Debug, Default, Patch, Deserialize)]
#[patch(attribute(derive(PartialEq, Debug, Deserialize)))]
struct B {
c: u32,
Expand All @@ -223,10 +223,12 @@ mod tests {
#[patch(name = "BPatch")]
b: B,
}
let mut b = B::default();
let b_patch: BPatch = serde_json::from_str(r#"{ "d": 1 }"#).unwrap();
b.apply(b_patch);
assert_eq!(b, B { c: 0, d: 1 });

let mut a = A {
b: B { c: 0, d: 0 },
};
let mut a = A { b };
let data = r#"{ "b": { "c": 1 } }"#;
let patch: APatch = serde_json::from_str(data).unwrap();
// assert_eq!(
Expand All @@ -239,7 +241,7 @@ mod tests {
assert_eq!(
a,
A {
b: B { c: 1, d: 0 }
b: B { c: 1, d: 1 }
}
);
}
Expand Down Expand Up @@ -286,7 +288,7 @@ mod tests {

#[test]
fn test_nested_generic() {
#[derive(PartialEq, Debug, Patch, Deserialize)]
#[derive(PartialEq, Debug, Default, Patch, Deserialize)]
#[patch(attribute(derive(PartialEq, Debug, Deserialize)))]
struct B<T>
where
Expand All @@ -303,17 +305,20 @@ mod tests {
b: B<u32>,
}

let mut a = A {
b: B { c: 0, d: 0 },
};
let mut b = B::default();
let b_patch: BPatch<u32> = serde_json::from_str(r#"{ "d": 1 }"#).unwrap();
b.apply(b_patch);
assert_eq!(b, B { c: 0, d: 1 });

let mut a = A { b };
let data = r#"{ "b": { "c": 1 } }"#;
let patch: APatch = serde_json::from_str(data).unwrap();

a.apply(patch);
assert_eq!(
a,
A {
b: B { c: 1, d: 0 }
b: B { c: 1, d: 1 }
}
);
}
Expand Down