()
| 548 | #[test] |
| 549 | #[ignore] |
| 550 | fn test_map() { |
| 551 | let data_file_path = get_data_file(); |
| 552 | let bytes = fs::read(&data_file_path).unwrap(); |
| 553 | |
| 554 | let mut fory = Fory::builder().compatible(true).xlang(true).build(); |
| 555 | fory.register::<Item>(102).unwrap(); |
| 556 | let mut reader = Reader::new(bytes.as_slice()); |
| 557 | |
| 558 | let str_map = HashMap::from([ |
| 559 | (Some("k1".to_string()), Some("v1".to_string())), |
| 560 | (None, Some("v2".to_string())), |
| 561 | (Some("k3".to_string()), None), |
| 562 | (Some("k4".to_string()), Some("v4".to_string())), |
| 563 | ]); |
| 564 | let item_map = HashMap::from([ |
| 565 | ( |
| 566 | Some("k1".to_string()), |
| 567 | Some(Item { |
| 568 | name: "item1".to_string(), |
| 569 | }), |
| 570 | ), |
| 571 | ( |
| 572 | None, |
| 573 | Some(Item { |
| 574 | name: "item2".to_string(), |
| 575 | }), |
| 576 | ), |
| 577 | (Some("k3".to_string()), None), |
| 578 | ( |
| 579 | Some("k4".to_string()), |
| 580 | Some(Item { |
| 581 | name: "item3".to_string(), |
| 582 | }), |
| 583 | ), |
| 584 | ]); |
| 585 | |
| 586 | let remote_str_map: HashMap<Option<String>, Option<String>> = |
| 587 | fory.deserialize_from(&mut reader).unwrap(); |
| 588 | assert_eq!(remote_str_map, str_map); |
| 589 | let data_bytes1 = fory.serialize(&remote_str_map).unwrap(); |
| 590 | let new_local_str_map: HashMap<Option<String>, Option<String>> = |
| 591 | fory.deserialize(&data_bytes1).unwrap(); |
| 592 | assert_eq!(new_local_str_map, str_map); |
| 593 | |
| 594 | let remote_item_map: HashMap<Option<String>, Option<Item>> = |
| 595 | fory.deserialize_from(&mut reader).unwrap(); |
| 596 | assert_eq!(remote_item_map, item_map); |
| 597 | let data_bytes2 = fory.serialize(&remote_item_map).unwrap(); |
| 598 | let new_local_item_map: HashMap<Option<String>, Option<Item>> = |
| 599 | fory.deserialize(&data_bytes2).unwrap(); |
| 600 | assert_eq!(new_local_item_map, item_map); |
| 601 | |
| 602 | let all_bytes = [data_bytes1.as_slice(), data_bytes2.as_slice()].concat(); |
| 603 | fs::write(&data_file_path, all_bytes).unwrap(); |
| 604 | } |
| 605 | |
| 606 | #[test] |
| 607 | #[ignore] |
nothing calls this directly
no test coverage detected