Skip to content

Commit afd80a4

Browse files
committed
byte order: Fix alignment issues in unit tests
1 parent 8ef2a2f commit afd80a4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/array.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,54 +216,66 @@ mod tests {
216216
#[test]
217217
fn from_bytes_u32() {
218218
let value: u32 = 42;
219+
let mut buf = maligned::align_first::<u8, maligned::A4>(4);
220+
buf.extend_from_slice(&value.to_ne_bytes());
219221
assert_eq!(
220222
[value],
221-
from_bytes::<u32>(&mut value.to_ne_bytes()).unwrap()
223+
from_bytes::<u32>(&mut buf).unwrap()
222224
);
223225
}
224226

225227
#[test]
226228
fn from_bytes_u64() {
227229
let value: u64 = u64::max_value();
230+
let mut buf = maligned::align_first::<u8, maligned::A8>(8);
231+
buf.extend_from_slice(&value.to_ne_bytes());
228232
assert_eq!(
229233
[value],
230-
from_bytes::<u64>(&mut value.to_ne_bytes()).unwrap()
234+
from_bytes::<u64>(&mut buf).unwrap()
231235
);
232236
}
233237

234238
#[test]
235239
fn from_bytes_i32() {
236240
let value: i32 = -42;
241+
let mut buf = maligned::align_first::<u8, maligned::A4>(4);
242+
buf.extend_from_slice(&value.to_ne_bytes());
237243
assert_eq!(
238244
[value],
239-
from_bytes::<i32>(&mut value.to_ne_bytes()).unwrap()
245+
from_bytes::<i32>(&mut buf).unwrap()
240246
);
241247
}
242248

243249
#[test]
244250
fn from_bytes_i64() {
245251
let value: i64 = i64::min_value();
252+
let mut buf = maligned::align_first::<u8, maligned::A8>(8);
253+
buf.extend_from_slice(&value.to_ne_bytes());
246254
assert_eq!(
247255
[value],
248-
from_bytes::<i64>(&mut value.to_ne_bytes()).unwrap()
256+
from_bytes::<i64>(&mut buf).unwrap()
249257
);
250258
}
251259

252260
#[test]
253261
fn from_bytes_f32() {
254262
let value: f32 = f32::min_value();
263+
let mut buf = maligned::align_first::<u8, maligned::A4>(4);
264+
buf.extend_from_slice(&value.to_ne_bytes());
255265
assert_eq!(
256266
[value],
257-
from_bytes::<f32>(&mut value.to_ne_bytes()).unwrap()
267+
from_bytes::<f32>(&mut buf).unwrap()
258268
);
259269
}
260270

261271
#[test]
262272
fn from_bytes_f64() {
263273
let value: f64 = f64::max_value();
274+
let mut buf = maligned::align_first::<u8, maligned::A8>(8);
275+
buf.extend_from_slice(&value.to_ne_bytes());
264276
assert_eq!(
265277
[value],
266-
from_bytes::<f64>(&mut value.to_ne_bytes()).unwrap()
278+
from_bytes::<f64>(&mut buf).unwrap()
267279
);
268280
}
269281

0 commit comments

Comments
 (0)