File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,3 +109,42 @@ unsafe impl<T: Bytes> AsContiguousBytes for [T] {
109109 self . as_ptr ( ) as * mut _
110110 }
111111}
112+
113+ #[ cfg( test) ]
114+ mod tests {
115+ use super :: * ;
116+
117+ #[ derive( Copy , Clone ) ]
118+ struct Byte ( u8 ) ;
119+
120+ unsafe impl Bytes for Byte { }
121+
122+ #[ test]
123+ fn it_uninitializes_to_a_garbage_value ( ) {
124+ let b = Byte :: uninitialized ( ) ;
125+
126+ assert_eq ! ( b. 0 , GARBAGE_VALUE ) ;
127+ }
128+
129+ #[ test]
130+ fn it_reports_size_correctly ( ) {
131+ assert_eq ! ( <Byte as Bytes >:: size( ) , 1 ) ;
132+ }
133+
134+ #[ test]
135+ fn it_provides_ptr_access ( ) {
136+ unsafe {
137+ let b = Byte ( 255 ) ;
138+ assert_eq ! ( * Bytes :: as_u8_ptr( & b) , 255 ) ;
139+ }
140+ }
141+
142+ #[ test]
143+ fn it_provides_mut_ptr_access ( ) {
144+ unsafe {
145+ let mut b = Byte ( 10 ) ;
146+ * Bytes :: as_mut_u8_ptr ( & mut b) = 42 ;
147+ assert_eq ! ( b. 0 , 42 ) ;
148+ }
149+ }
150+ }
You can’t perform that action at this time.
0 commit comments