diff --git a/src/header/internals/cell.rs b/src/header/internals/cell.rs index e76579f1..65a45fdb 100644 --- a/src/header/internals/cell.rs +++ b/src/header/internals/cell.rs @@ -129,3 +129,76 @@ impl Clone for PtrMapCell where Box = OptCell::new(None); + one.set(1); + assert_eq!(*one,Some(1)); + } + + #[test] + fn test_opt_cell_clone() { + let one:OptCell = OptCell::new(Some(3)); + let stored = *one.clone(); + assert_eq!(stored,Some(3)); + } + + + #[test] + fn test_ptr_map_cell_none() { + let type_id = TypeId::of::(); + let pm:PtrMapCell = PtrMapCell::new(); + assert_eq!(pm.get(type_id),None); + } + + #[test] + fn test_ptr_map_cell_one() { + let type_id = TypeId::of::(); + let pm:PtrMapCell = PtrMapCell::new(); + unsafe { pm.insert(type_id, Box::new("a".to_string())); } + assert_eq!(pm.get(type_id), Some(&"a".to_string())); + assert_eq!(unsafe {pm.one()}, "a"); + } + + #[test] + fn test_ptr_map_cell_two() { + let type_id = TypeId::of::(); + let type_id2 = TypeId::of::>(); + let pm:PtrMapCell = PtrMapCell::new(); + unsafe { pm.insert(type_id, Box::new("a".to_string())); } + unsafe { pm.insert(type_id2, Box::new("b".to_string())); } + assert_eq!(pm.get(type_id), Some(&"a".to_string())); + assert_eq!(pm.get(type_id2), Some(&"b".to_string())); + } + + #[test] + fn test_ptr_map_cell_many() { + let id1 = TypeId::of::(); + let id2 = TypeId::of::>(); + let id3 = TypeId::of::>(); + let pm:PtrMapCell = PtrMapCell::new(); + unsafe { pm.insert(id1, Box::new("a".to_string())); } + unsafe { pm.insert(id2, Box::new("b".to_string())); } + unsafe { pm.insert(id3, Box::new("c".to_string())); } + assert_eq!(pm.get(id1), Some(&"a".to_string())); + assert_eq!(pm.get(id2), Some(&"b".to_string())); + assert_eq!(pm.get(id3), Some(&"c".to_string())); + } + + + #[test] + fn test_ptr_map_cell_clone() { + let type_id = TypeId::of::(); + let pm:PtrMapCell = PtrMapCell::new(); + unsafe { pm.insert(type_id, Box::new("a".to_string())); } + let cloned = pm.clone(); + assert_eq!(cloned.get(type_id), Some(&"a".to_string())); + } + +}