aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2017-11-13 11:26:47 -0800
committerAndrew Gallant <jamslam@gmail.com>2017-11-29 16:07:51 -0500
commit098064b8c94c42e86deb7689cb4648ca39f54b2c (patch)
tree4dc77daedb1695cfe04f3f12849d9b0ce113fdce /src
parentfef20557fa42c4f9f3f74ef0df08cf48fe80aaaa (diff)
downloadbyteorder-098064b8c94c42e86deb7689cb4648ca39f54b2c.tar.gz
Fix prop_ext_[u]int_*::native_endian on BE targets
The similar `big_endian` tests were using an offset to read from the end of the written `u64`, but the `native_endian` tests were reading directly, just like the `little_endian` tests. That's of course only correct when the target actually is little endian. That `big_endian` offset is now sliced directly, instead of cloning into another vector, and then this logic is also used in the `native_endian` test, depending on the current `#[cfg(target_endian)]`. Fixes #102.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b60fe7c..35c0069 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2865,9 +2865,8 @@ mod stdtests {
fn prop(n: $ty_int) -> bool {
let mut wtr = vec![];
wtr.$write::<BigEndian>(n.clone()).unwrap();
- let mut rdr = Vec::new();
- rdr.extend(wtr[wtr.len()-$bytes..].iter().map(|&x| x));
- let mut rdr = Cursor::new(rdr);
+ let offset = wtr.len() - $bytes;
+ let mut rdr = Cursor::new(&mut wtr[offset..]);
n == rdr.$read::<BigEndian>($bytes).unwrap()
}
qc_sized(prop as fn($ty_int) -> bool, $max);
@@ -2889,7 +2888,12 @@ mod stdtests {
fn prop(n: $ty_int) -> bool {
let mut wtr = vec![];
wtr.$write::<NativeEndian>(n.clone()).unwrap();
- let mut rdr = Cursor::new(wtr);
+ let offset = if cfg!(target_endian = "big") {
+ wtr.len() - $bytes
+ } else {
+ 0
+ };
+ let mut rdr = Cursor::new(&mut wtr[offset..]);
n == rdr.$read::<NativeEndian>($bytes).unwrap()
}
qc_sized(prop as fn($ty_int) -> bool, $max);