parent
ac5c59043c
commit
dbf29d2964
@ -0,0 +1,156 @@
|
||||
From 39e05345064ec1783f58a14ce896d521ef3cfc3a Mon Sep 17 00:00:00 2001
|
||||
From: m4b <m4b.github.io@gmail.com>
|
||||
Date: Sat, 2 Dec 2017 00:56:46 -0800
|
||||
Subject: [PATCH] build: make tests more robust on various architectures for
|
||||
smaller pointers + different endianness. ref #20
|
||||
|
||||
---
|
||||
src/greater.rs | 10 +++++-----
|
||||
src/lesser.rs | 6 +++---
|
||||
src/lib.rs | 5 ++++-
|
||||
tests/api.rs | 12 ++++++------
|
||||
4 files changed, 18 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/src/greater.rs b/src/greater.rs
|
||||
index 99560b1..cffdbbf 100644
|
||||
--- a/src/greater.rs
|
||||
+++ b/src/greater.rs
|
||||
@@ -60,7 +60,7 @@ pub trait Cread<Ctx, I = usize> : Index<I> + Index<RangeFrom<I>>
|
||||
/// use scroll::Cread;
|
||||
///
|
||||
/// let bytes = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,];
|
||||
- /// let foo = bytes.cread::<usize>(0);
|
||||
+ /// let foo = bytes.cread::<i64>(0);
|
||||
/// let bar = bytes.cread::<u32>(8);
|
||||
/// assert_eq!(foo, 1);
|
||||
/// assert_eq!(bar, 0xbeef);
|
||||
@@ -108,9 +108,9 @@ pub trait Cwrite<Ctx: Copy, I = usize>: Index<I> + IndexMut<RangeFrom<I>> {
|
||||
/// ```
|
||||
/// use scroll::{Cwrite, Cread};
|
||||
/// let mut bytes = [0x0; 0x10];
|
||||
- /// bytes.cwrite::<usize>(42, 0);
|
||||
+ /// bytes.cwrite::<i64>(42, 0);
|
||||
/// bytes.cwrite::<u32>(0xdeadbeef, 8);
|
||||
- /// assert_eq!(bytes.cread::<usize>(0), 42);
|
||||
+ /// assert_eq!(bytes.cread::<i64>(0), 42);
|
||||
/// assert_eq!(bytes.cread::<u32>(8), 0xdeadbeef);
|
||||
#[inline]
|
||||
fn cwrite<N: IntoCtx<Ctx, <Self as Index<RangeFrom<I>>>::Output>>(&mut self, n: N, offset: I) where Ctx: Default {
|
||||
@@ -124,9 +124,9 @@ pub trait Cwrite<Ctx: Copy, I = usize>: Index<I> + IndexMut<RangeFrom<I>> {
|
||||
/// ```
|
||||
/// use scroll::{Cwrite, Cread, LE, BE};
|
||||
/// let mut bytes = [0x0; 0x10];
|
||||
- /// bytes.cwrite_with::<usize>(42, 0, LE);
|
||||
+ /// bytes.cwrite_with::<i64>(42, 0, LE);
|
||||
/// bytes.cwrite_with::<u32>(0xdeadbeef, 8, BE);
|
||||
- /// assert_eq!(bytes.cread::<usize>(0), 42);
|
||||
+ /// assert_eq!(bytes.cread::<i64>(0), 42);
|
||||
/// assert_eq!(bytes.cread::<u32>(8), 0xefbeadde);
|
||||
#[inline]
|
||||
fn cwrite_with<N: IntoCtx<Ctx, <Self as Index<RangeFrom<I>>>::Output>>(&mut self, n: N, offset: I, ctx: Ctx) {
|
||||
diff --git a/src/lesser.rs b/src/lesser.rs
|
||||
index 1258216..a26042a 100644
|
||||
--- a/src/lesser.rs
|
||||
+++ b/src/lesser.rs
|
||||
@@ -15,13 +15,13 @@ use ctx::{FromCtx, IntoCtx, SizeWith};
|
||||
///
|
||||
/// #[repr(packed)]
|
||||
/// struct Foo {
|
||||
-/// foo: usize,
|
||||
+/// foo: i64,
|
||||
/// bar: u32,
|
||||
/// }
|
||||
///
|
||||
/// impl ctx::FromCtx<scroll::Endian> for Foo {
|
||||
/// fn from_ctx(bytes: &[u8], ctx: scroll::Endian) -> Self {
|
||||
-/// Foo { foo: bytes.pread_with::<usize>(0, ctx).unwrap(), bar: bytes.pread_with::<u32>(8, ctx).unwrap() }
|
||||
+/// Foo { foo: bytes.pread_with::<i64>(0, ctx).unwrap(), bar: bytes.pread_with::<u32>(8, ctx).unwrap() }
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
@@ -35,7 +35,7 @@ use ctx::{FromCtx, IntoCtx, SizeWith};
|
||||
///
|
||||
/// let bytes_ = [0x0b,0x0b,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,];
|
||||
/// let mut bytes = Cursor::new(bytes_);
|
||||
-/// let foo = bytes.ioread::<usize>().unwrap();
|
||||
+/// let foo = bytes.ioread::<i64>().unwrap();
|
||||
/// let bar = bytes.ioread::<u32>().unwrap();
|
||||
/// assert_eq!(foo, 0xb0b);
|
||||
/// assert_eq!(bar, 0xbeef);
|
||||
diff --git a/src/lib.rs b/src/lib.rs
|
||||
index 2f9ecda..4311485 100644
|
||||
--- a/src/lib.rs
|
||||
+++ b/src/lib.rs
|
||||
@@ -78,7 +78,7 @@
|
||||
//! let mut bytes = Cursor::new(bytes_);
|
||||
//!
|
||||
//! // this will bump the cursor's Seek
|
||||
-//! let foo = bytes.ioread::<usize>().unwrap();
|
||||
+//! let foo = bytes.ioread::<u64>().unwrap();
|
||||
//! // ..ditto
|
||||
//! let bar = bytes.ioread::<u32>().unwrap();
|
||||
//! ```
|
||||
@@ -222,7 +222,10 @@ mod tests {
|
||||
let bytes: [u8; 2] = [0x7e, 0xef];
|
||||
let b = &bytes[..];
|
||||
let byte: u16 = b.pread(0).unwrap();
|
||||
+ #[cfg(target_endian = "little")]
|
||||
assert_eq!(0xef7e, byte);
|
||||
+ #[cfg(target_endian = "big")]
|
||||
+ assert_eq!(0x7eef, byte);
|
||||
}
|
||||
|
||||
#[test]
|
||||
diff --git a/tests/api.rs b/tests/api.rs
|
||||
index e3d8574..942d5af 100644
|
||||
--- a/tests/api.rs
|
||||
+++ b/tests/api.rs
|
||||
@@ -171,13 +171,13 @@ fn lifetime_passthrough() {
|
||||
#[derive(Default)]
|
||||
#[repr(packed)]
|
||||
struct Foo {
|
||||
- foo: usize,
|
||||
+ foo: i64,
|
||||
bar: u32,
|
||||
}
|
||||
|
||||
impl scroll::ctx::FromCtx<scroll::Endian> for Foo {
|
||||
fn from_ctx(bytes: &[u8], ctx: scroll::Endian) -> Self {
|
||||
- Foo { foo: bytes.cread_with::<usize>(0, ctx), bar: bytes.cread_with::<u32>(8, ctx) }
|
||||
+ Foo { foo: bytes.cread_with::<i64>(0, ctx), bar: bytes.cread_with::<u32>(8, ctx) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ fn ioread_api() {
|
||||
use scroll::IOread;
|
||||
let bytes_ = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,];
|
||||
let mut bytes = Cursor::new(bytes_);
|
||||
- let foo = bytes.ioread::<usize>().unwrap();
|
||||
+ let foo = bytes.ioread::<i64>().unwrap();
|
||||
let bar = bytes.ioread::<u32>().unwrap();
|
||||
assert_eq!(foo, 1);
|
||||
assert_eq!(bar, 0xbeef);
|
||||
@@ -223,7 +223,7 @@ impl scroll::ctx::FromCtx<scroll::Endian> for Bar {
|
||||
fn cread_api() {
|
||||
use scroll::Cread;
|
||||
let bytes = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xef,0xbe,0x00,0x00,];
|
||||
- let foo = bytes.cread::<usize>(0);
|
||||
+ let foo = bytes.cread::<u64>(0);
|
||||
let bar = bytes.cread::<u32>(8);
|
||||
assert_eq!(foo, 1);
|
||||
assert_eq!(bar, 0xbeef);
|
||||
@@ -251,9 +251,9 @@ fn cwrite_api() {
|
||||
use scroll::Cwrite;
|
||||
use scroll::Cread;
|
||||
let mut bytes = [0x0; 0x10];
|
||||
- bytes.cwrite::<usize>(42, 0);
|
||||
+ bytes.cwrite::<u64>(42, 0);
|
||||
bytes.cwrite::<u32>(0xdeadbeef, 8);
|
||||
- assert_eq!(bytes.cread::<usize>(0), 42);
|
||||
+ assert_eq!(bytes.cread::<u64>(0), 42);
|
||||
assert_eq!(bytes.cread::<u32>(8), 0xdeadbeef);
|
||||
}
|
||||
|
||||
--
|
||||
2.15.1
|
||||
|
Loading…
Reference in new issue