Merge pull request #552 from winding-lines/coverage
test(internal): increasing test coverage of internal/cell module
This commit is contained in:
@@ -129,3 +129,76 @@ impl<V: ?Sized + fmt::Debug + Any + 'static> Clone for PtrMapCell<V> where Box<V
|
||||
cell
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::any::TypeId;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_opt_cell_set() {
|
||||
let one:OptCell<u32> = OptCell::new(None);
|
||||
one.set(1);
|
||||
assert_eq!(*one,Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_opt_cell_clone() {
|
||||
let one:OptCell<u32> = 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::<u32>();
|
||||
let pm:PtrMapCell<u32> = PtrMapCell::new();
|
||||
assert_eq!(pm.get(type_id),None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ptr_map_cell_one() {
|
||||
let type_id = TypeId::of::<String>();
|
||||
let pm:PtrMapCell<String> = 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::<String>();
|
||||
let type_id2 = TypeId::of::<Vec<u8>>();
|
||||
let pm:PtrMapCell<String> = 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::<String>();
|
||||
let id2 = TypeId::of::<Vec<u8>>();
|
||||
let id3 = TypeId::of::<OptCell<String>>();
|
||||
let pm:PtrMapCell<String> = 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::<String>();
|
||||
let pm:PtrMapCell<String> = 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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user