cross: compile tests with the fmt feature so we can use assert_eq

This commit is contained in:
2022-08-17 21:06:23 -07:00
parent 3ed4cd5059
commit 198cc16f3f
3 changed files with 51 additions and 48 deletions

1
Cargo.lock generated
View File

@@ -346,6 +346,7 @@ dependencies = [
name = "coremem_cross" name = "coremem_cross"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"coremem_cross",
"serde", "serde",
] ]

View File

@@ -11,3 +11,5 @@ fmt = []
[dependencies] [dependencies]
serde = { version = "1.0", optional = true } # MIT or Apache 2.0 serde = { version = "1.0", optional = true } # MIT or Apache 2.0
[dev-dependencies]
coremem_cross = { path = ".", default-features = false, features = ["fmt"] }

View File

@@ -190,64 +190,64 @@ mod test {
fn dim_slice_indices() { fn dim_slice_indices() {
let s = DimSlice::new(Vec3u::new(4, 3, 2), &[()]); let s = DimSlice::new(Vec3u::new(4, 3, 2), &[()]);
let mut i = s.indices(); let mut i = s.indices();
assert!(i.next().unwrap() == Vec3u::new(0, 0, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(0, 0, 0));
assert!(i.next().unwrap() == Vec3u::new(1, 0, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(1, 0, 0));
assert!(i.next().unwrap() == Vec3u::new(2, 0, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(2, 0, 0));
assert!(i.next().unwrap() == Vec3u::new(3, 0, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(3, 0, 0));
assert!(i.next().unwrap() == Vec3u::new(0, 1, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(0, 1, 0));
assert!(i.next().unwrap() == Vec3u::new(1, 1, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(1, 1, 0));
assert!(i.next().unwrap() == Vec3u::new(2, 1, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(2, 1, 0));
assert!(i.next().unwrap() == Vec3u::new(3, 1, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(3, 1, 0));
assert!(i.next().unwrap() == Vec3u::new(0, 2, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(0, 2, 0));
assert!(i.next().unwrap() == Vec3u::new(1, 2, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(1, 2, 0));
assert!(i.next().unwrap() == Vec3u::new(2, 2, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(2, 2, 0));
assert!(i.next().unwrap() == Vec3u::new(3, 2, 0)); assert_eq!(i.next().unwrap(), Vec3u::new(3, 2, 0));
assert!(i.next().unwrap() == Vec3u::new(0, 0, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(0, 0, 1));
assert!(i.next().unwrap() == Vec3u::new(1, 0, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(1, 0, 1));
assert!(i.next().unwrap() == Vec3u::new(2, 0, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(2, 0, 1));
assert!(i.next().unwrap() == Vec3u::new(3, 0, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(3, 0, 1));
assert!(i.next().unwrap() == Vec3u::new(0, 1, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(0, 1, 1));
assert!(i.next().unwrap() == Vec3u::new(1, 1, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(1, 1, 1));
assert!(i.next().unwrap() == Vec3u::new(2, 1, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(2, 1, 1));
assert!(i.next().unwrap() == Vec3u::new(3, 1, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(3, 1, 1));
assert!(i.next().unwrap() == Vec3u::new(0, 2, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(0, 2, 1));
assert!(i.next().unwrap() == Vec3u::new(1, 2, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(1, 2, 1));
assert!(i.next().unwrap() == Vec3u::new(2, 2, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(2, 2, 1));
assert!(i.next().unwrap() == Vec3u::new(3, 2, 1)); assert_eq!(i.next().unwrap(), Vec3u::new(3, 2, 1));
assert!(i.next() == None); assert_eq!(i.next(), None);
assert!(i.next() == None); assert_eq!(i.next(), None);
} }
#[test] #[test]
fn dim_slice_indices_zero_dim() { fn dim_slice_indices_zero_dim() {
let s = DimSlice::new(Vec3u::new(4, 3, 0), &[()]); let s = DimSlice::new(Vec3u::new(4, 3, 0), &[()]);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
let s = DimSlice::new(Vec3u::new(4, 0, 2), &[()]); let s = DimSlice::new(Vec3u::new(4, 0, 2), &[()]);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
let s = DimSlice::new(Vec3u::new(0, 3, 2), &[()]); let s = DimSlice::new(Vec3u::new(0, 3, 2), &[()]);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
let s = DimSlice::new(Vec3u::new(3, 0, 0), &[()]); let s = DimSlice::new(Vec3u::new(3, 0, 0), &[()]);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
let s = DimSlice::new(Vec3u::new(0, 1, 0), &[()]); let s = DimSlice::new(Vec3u::new(0, 1, 0), &[()]);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
let s = DimSlice::new(Vec3u::new(0, 0, 2), &[()]); let s = DimSlice::new(Vec3u::new(0, 0, 2), &[()]);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
assert!(s.indices().next() == None); assert_eq!(s.indices().next(), None);
} }
#[test] #[test]
@@ -259,13 +259,13 @@ mod test {
]; ];
let s = DimSlice::new(Vec3u::new(1, 2, 3), &data); let s = DimSlice::new(Vec3u::new(1, 2, 3), &data);
let mut i = s.enumerated(); let mut i = s.enumerated();
assert!(i.next().unwrap() == (Vec3u::new(0, 0, 0), &10)); assert_eq!(i.next().unwrap(), (Vec3u::new(0, 0, 0), &10));
assert!(i.next().unwrap() == (Vec3u::new(0, 1, 0), &11)); assert_eq!(i.next().unwrap(), (Vec3u::new(0, 1, 0), &11));
assert!(i.next().unwrap() == (Vec3u::new(0, 0, 1), &20)); assert_eq!(i.next().unwrap(), (Vec3u::new(0, 0, 1), &20));
assert!(i.next().unwrap() == (Vec3u::new(0, 1, 1), &21)); assert_eq!(i.next().unwrap(), (Vec3u::new(0, 1, 1), &21));
assert!(i.next().unwrap() == (Vec3u::new(0, 0, 2), &30)); assert_eq!(i.next().unwrap(), (Vec3u::new(0, 0, 2), &30));
assert!(i.next().unwrap() == (Vec3u::new(0, 1, 2), &31)); assert_eq!(i.next().unwrap(), (Vec3u::new(0, 1, 2), &31));
assert!(i.next() == None); assert_eq!(i.next(), None);
} }
#[test] #[test]
@@ -279,16 +279,16 @@ mod test {
let mut i = s.enumerated(); let mut i = s.enumerated();
let (idx, v) = i.next().unwrap(); let (idx, v) = i.next().unwrap();
assert!(idx == Vec3u::new(0, 0, 0)); assert_eq!(idx, Vec3u::new(0, 0, 0));
*v = 100; *v = 100;
let (idx, v) = i.next().unwrap(); let (idx, v) = i.next().unwrap();
assert!(idx == Vec3u::new(1, 0, 0)); assert_eq!(idx, Vec3u::new(1, 0, 0));
*v = 110; *v = 110;
i.next().unwrap(); i.next().unwrap();
let (idx, v) = i.next().unwrap(); let (idx, v) = i.next().unwrap();
assert!(idx == Vec3u::new(1, 0, 1)); assert_eq!(idx, Vec3u::new(1, 0, 1));
*v = 210; *v = 210;
assert_eq!(data, [100, 110, 20, 210, 30, 31]); assert_eq!(data, [100, 110, 20, 210, 30, 31]);