Skip to content

Commit c89b1ca

Browse files
committed
update testcase for nestinig name feature
1 parent d5c6593 commit c89b1ca

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/src/lib.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ mod tests {
210210

211211
#[test]
212212
fn test_nested() {
213-
#[derive(PartialEq, Debug, Patch, Deserialize)]
213+
#[derive(PartialEq, Debug, Default, Patch, Deserialize)]
214214
#[patch(attribute(derive(PartialEq, Debug, Deserialize)))]
215215
struct B {
216216
c: u32,
@@ -223,10 +223,12 @@ mod tests {
223223
#[patch(name = "BPatch")]
224224
b: B,
225225
}
226+
let mut b = B::default();
227+
let b_patch: BPatch = serde_json::from_str(r#"{ "d": 1 }"#).unwrap();
228+
b.apply(b_patch);
229+
assert_eq!(b, B { c: 0, d: 1 });
226230

227-
let mut a = A {
228-
b: B { c: 0, d: 0 },
229-
};
231+
let mut a = A { b };
230232
let data = r#"{ "b": { "c": 1 } }"#;
231233
let patch: APatch = serde_json::from_str(data).unwrap();
232234
// assert_eq!(
@@ -239,7 +241,7 @@ mod tests {
239241
assert_eq!(
240242
a,
241243
A {
242-
b: B { c: 1, d: 0 }
244+
b: B { c: 1, d: 1 }
243245
}
244246
);
245247
}
@@ -286,7 +288,7 @@ mod tests {
286288

287289
#[test]
288290
fn test_nested_generic() {
289-
#[derive(PartialEq, Debug, Patch, Deserialize)]
291+
#[derive(PartialEq, Debug, Default, Patch, Deserialize)]
290292
#[patch(attribute(derive(PartialEq, Debug, Deserialize)))]
291293
struct B<T>
292294
where
@@ -303,17 +305,20 @@ mod tests {
303305
b: B<u32>,
304306
}
305307

306-
let mut a = A {
307-
b: B { c: 0, d: 0 },
308-
};
308+
let mut b = B::default();
309+
let b_patch: BPatch<u32> = serde_json::from_str(r#"{ "d": 1 }"#).unwrap();
310+
b.apply(b_patch);
311+
assert_eq!(b, B { c: 0, d: 1 });
312+
313+
let mut a = A { b };
309314
let data = r#"{ "b": { "c": 1 } }"#;
310315
let patch: APatch = serde_json::from_str(data).unwrap();
311316

312317
a.apply(patch);
313318
assert_eq!(
314319
a,
315320
A {
316-
b: B { c: 1, d: 0 }
321+
b: B { c: 1, d: 1 }
317322
}
318323
);
319324
}

0 commit comments

Comments
 (0)