MCPcopy Create free account
hub / github.com/apache/fory / test_map

Function test_map

rust/tests/tests/test_cross_language.rs:550–604  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

548#[test]
549#[ignore]
550fn 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]

Callers

nothing calls this directly

Calls 12

SomeFunction · 0.85
deserialize_fromMethod · 0.80
get_data_fileFunction · 0.70
serializeMethod · 0.65
deserializeMethod · 0.65
readFunction · 0.50
writeFunction · 0.50
unwrapMethod · 0.45
buildMethod · 0.45
xlangMethod · 0.45
compatibleMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected