Skip to content

Commit d64a58a

Browse files
committed
Additional tests
1 parent 5586786 commit d64a58a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/traits/bytes.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)