Skip to content

Commit

Permalink
Use assert_eq! instead of assert! where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 24, 2021
1 parent 76f3956 commit 935383b
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion block2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct. For example, to create a block that adds two `i32`s, we could write:
use block2::ConcreteBlock;
let block = ConcreteBlock::new(|a: i32, b: i32| a + b);
let block = block.copy();
assert!(unsafe { block.call((5, 8)) } == 13);
assert_eq!(unsafe { block.call((5, 8)) }, 13);
```

It is important to copy your block to the heap (with the `copy` method) before
Expand Down
2 changes: 1 addition & 1 deletion block2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct. For example, to create a block that adds two `i32`s, we could write:
# use block2::ConcreteBlock;
let block = ConcreteBlock::new(|a: i32, b: i32| a + b);
let block = block.copy();
assert!(unsafe { block.call((5, 8)) } == 13);
assert_eq!(unsafe { block.call((5, 8)) }, 13);
```
It is important to copy your block to the heap (with the `copy` method) before
Expand Down
16 changes: 8 additions & 8 deletions objc2-encode/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ mod tests {
let i = Encoding::Int;
let p = Encoding::Pointer(&Encoding::Int);

assert!(p == p);
assert!(p != i);
assert_eq!(p, p);
assert_ne!(p, i);
}

#[test]
Expand All @@ -213,8 +213,8 @@ mod tests {
let i = Encoding::Int;
let c = Encoding::Char;

assert!(i == i);
assert!(i != c);
assert_eq!(i, i);
assert_ne!(i, c);
}

#[test]
Expand All @@ -227,8 +227,8 @@ mod tests {
#[test]
fn test_struct_eq() {
let s = Encoding::Struct("CGPoint", &[Encoding::Char, Encoding::Int]);
assert!(s == s);
assert!(s != Encoding::Int);
assert_eq!(s, s);
assert_ne!(s, Encoding::Int);
}

#[test]
Expand All @@ -241,7 +241,7 @@ mod tests {
#[test]
fn test_union_eq() {
let u = Encoding::Union("Onion", &[Encoding::Char, Encoding::Int]);
assert!(u == u);
assert!(u != Encoding::Int);
assert_eq!(u, u);
assert_ne!(u, Encoding::Int);
}
}
2 changes: 1 addition & 1 deletion objc2-foundation/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ mod tests {
fn test_iter() {
let array = sample_array(4);

assert!(array.iter().count() == 4);
assert_eq!(array.iter().count(), 4);
assert!(array
.iter()
.enumerate()
Expand Down
8 changes: 4 additions & 4 deletions objc2-foundation/src/enumerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ impl<'a, C: INSFastEnumeration> NSFastEnumerator<'a, C> {
if let Some(buf) = next_buf {
// Check if the collection was mutated
if let Some(mutations) = mutations {
assert!(
mutations == unsafe { *self.state.mutations_ptr },
assert_eq!(
mutations, unsafe { *self.state.mutations_ptr },
"Mutation detected during enumeration of object {:p}",
self.object
);
Expand Down Expand Up @@ -178,7 +178,7 @@ mod tests {
let array = NSArray::from_vec(vec);

let enumerator = array.iter();
assert!(enumerator.count() == 4);
assert_eq!(enumerator.count(), 4);

let enumerator = array.iter();
assert!(enumerator.enumerate().all(|(i, obj)| obj.get() == i as u32));
Expand All @@ -190,7 +190,7 @@ mod tests {
let array = NSArray::from_vec(vec);

let enumerator = array.enumerator();
assert!(enumerator.count() == 4);
assert_eq!(enumerator.count(), 4);

let enumerator = array.enumerator();
assert!(enumerator.enumerate().all(|(i, obj)| obj.get() == i as u32));
Expand Down
29 changes: 14 additions & 15 deletions objc2/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ impl ClassDecl {
{
let encs = F::Args::ENCODINGS;
let sel_args = count_args(sel);
assert!(
sel_args == encs.len(),
assert_eq!(
sel_args,
encs.len(),
"Selector accepts {} arguments, but function accepts {}",
sel_args,
encs.len(),
Expand Down Expand Up @@ -217,8 +218,9 @@ impl ClassDecl {
{
let encs = F::Args::ENCODINGS;
let sel_args = count_args(sel);
assert!(
sel_args == encs.len(),
assert_eq!(
sel_args,
encs.len(),
"Selector accepts {} arguments, but function accepts {}",
sel_args,
encs.len(),
Expand Down Expand Up @@ -319,8 +321,9 @@ impl ProtocolDecl {
{
let encs = Args::ENCODINGS;
let sel_args = count_args(sel);
assert!(
sel_args == encs.len(),
assert_eq!(
sel_args,
encs.len(),
"Selector accepts {} arguments, but function accepts {}",
sel_args,
encs.len(),
Expand Down Expand Up @@ -380,19 +383,15 @@ mod tests {
fn test_custom_class() {
// Registering the custom class is in test_utils
let obj = test_utils::custom_object();
unsafe {
let _: () = msg_send![obj, setFoo: 13u32];
let result: u32 = msg_send![obj, foo];
assert!(result == 13);
}
let _: () = unsafe { msg_send![obj, setFoo: 13u32] };
let result: u32 = unsafe { msg_send![obj, foo] };
assert_eq!(result, 13);
}

#[test]
fn test_class_method() {
let cls = test_utils::custom_class();
unsafe {
let result: u32 = msg_send![cls, classFoo];
assert!(result == 7);
}
let result: u32 = unsafe { msg_send![cls, classFoo] };
assert_eq!(result, 7);
}
}
8 changes: 4 additions & 4 deletions objc2/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ mod tests {
let _: () = msg_send![obj, setFoo: 4u32];
msg_send![obj, foo]
};
assert!(result == 4);
assert_eq!(result, 4);
}

#[test]
Expand All @@ -375,7 +375,7 @@ mod tests {
c: 3,
d: 4,
};
assert!(result == expected);
assert_eq!(result, expected);
}

#[cfg(not(feature = "verify_message"))]
Expand Down Expand Up @@ -411,11 +411,11 @@ mod tests {
unsafe {
let _: () = msg_send![obj, setFoo: 4u32];
let foo: u32 = msg_send![super(obj, superclass), foo];
assert!(foo == 4);
assert_eq!(foo, 4);

// The subclass is overriden to return foo + 2
let foo: u32 = msg_send![obj, foo];
assert!(foo == 6);
assert_eq!(foo, 6);
}
}

Expand Down
10 changes: 5 additions & 5 deletions objc2/src/rc/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,16 @@ mod tests {
let obj: *mut Object = msg_send![obj, init];
Id::new(NonNull::new_unchecked(obj))
};
assert!(retain_count(&obj) == 1);
assert_eq!(retain_count(&obj), 1);

let obj: Id<_, Shared> = obj.into();
assert!(retain_count(&obj) == 1);
assert_eq!(retain_count(&obj), 1);

let cloned = obj.clone();
assert!(retain_count(&cloned) == 2);
assert!(retain_count(&obj) == 2);
assert_eq!(retain_count(&cloned), 2);
assert_eq!(retain_count(&obj), 2);

drop(obj);
assert!(retain_count(&cloned) == 1);
assert_eq!(retain_count(&cloned), 1);
}
}
20 changes: 10 additions & 10 deletions objc2/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ mod tests {
fn test_ivar() {
let cls = test_utils::custom_class();
let ivar = cls.instance_variable("_foo").unwrap();
assert!(ivar.name() == "_foo");
assert_eq!(ivar.name(), "_foo");
assert!(ivar.type_encoding() == &<u32>::ENCODING);
assert!(ivar.offset() > 0);

Expand All @@ -560,8 +560,8 @@ mod tests {
let cls = test_utils::custom_class();
let sel = Sel::register("foo");
let method = cls.instance_method(sel).unwrap();
assert!(method.name().name() == "foo");
assert!(method.arguments_count() == 2);
assert_eq!(method.name().name(), "foo");
assert_eq!(method.arguments_count(), 2);
assert!(*method.return_type() == <u32>::ENCODING);
assert!(*method.argument_type(1).unwrap() == Sel::ENCODING);

Expand All @@ -572,18 +572,18 @@ mod tests {
#[test]
fn test_class() {
let cls = test_utils::custom_class();
assert!(cls.name() == "CustomObject");
assert_eq!(cls.name(), "CustomObject");
assert!(cls.instance_size() > 0);
assert!(cls.superclass().is_none());

assert!(Class::get(cls.name()) == Some(cls));
assert_eq!(Class::get(cls.name()), Some(cls));

let metaclass = cls.metaclass();
// The metaclass of a root class is a subclass of the root class
assert!(metaclass.superclass().unwrap() == cls);
assert_eq!(metaclass.superclass().unwrap(), cls);

let subclass = test_utils::custom_subclass();
assert!(subclass.superclass().unwrap() == cls);
assert_eq!(subclass.superclass().unwrap(), cls);
}

#[test]
Expand All @@ -596,7 +596,7 @@ mod tests {
#[test]
fn test_protocol() {
let proto = test_utils::custom_protocol();
assert!(proto.name() == "CustomProtocol");
assert_eq!(proto.name(), "CustomProtocol");
let class = test_utils::custom_class();
assert!(class.conforms_to(proto));
let class_protocols = class.adopted_protocols();
Expand Down Expand Up @@ -631,12 +631,12 @@ mod tests {
#[test]
fn test_object() {
let mut obj = test_utils::custom_object();
assert!(obj.class() == test_utils::custom_class());
assert_eq!(obj.class(), test_utils::custom_class());
let result: u32 = unsafe {
obj.set_ivar("_foo", 4u32);
*obj.get_ivar("_foo")
};
assert!(result == 4);
assert_eq!(result, 4);
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion objc2/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::declare::{ClassDecl, ProtocolDecl};
use crate::runtime::{Class, Object, Protocol, Sel};
use crate::{ffi, Encode, Encoding, MessageReceiver};

#[derive(Debug)]
pub(crate) struct CustomObject {
obj: *mut Object,
}
Expand Down Expand Up @@ -51,7 +52,7 @@ impl Drop for CustomObject {
}
}

#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
#[repr(C)]
pub(crate) struct CustomStruct {
pub(crate) a: u64,
Expand Down
8 changes: 4 additions & 4 deletions tests/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ mod tests {
#[test]
fn test_int_block() {
unsafe {
assert!(invoke_int_block(get_int_block()) == 7);
assert!(invoke_int_block(get_int_block_with(13)) == 13);
assert_eq!(invoke_int_block(get_int_block()), 7);
assert_eq!(invoke_int_block(get_int_block_with(13)), 13);
}
}

#[test]
fn test_add_block() {
unsafe {
assert!(invoke_add_block(get_add_block(), 5) == 12);
assert!(invoke_add_block(get_add_block_with(3), 5) == 8);
assert_eq!(invoke_add_block(get_add_block(), 5), 12);
assert_eq!(invoke_add_block(get_add_block_with(3), 5), 8);
}
}
}
14 changes: 7 additions & 7 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,41 @@ mod tests {
fn test_call_block() {
let block = get_int_block_with(13);
unsafe {
assert!(block.call(()) == 13);
assert_eq!(block.call(()), 13);
}
}

#[test]
fn test_call_block_args() {
let block = get_add_block_with(13);
unsafe {
assert!(block.call((2,)) == 15);
assert_eq!(block.call((2,)), 15);
}
}

#[test]
fn test_create_block() {
let block = ConcreteBlock::new(|| 13);
let result = invoke_int_block(&block);
assert!(result == 13);
assert_eq!(result, 13);
}

#[test]
fn test_create_block_args() {
let block = ConcreteBlock::new(|a: i32| a + 5);
let result = invoke_add_block(&block, 6);
assert!(result == 11);
assert_eq!(result, 11);
}

#[test]
fn test_concrete_block_copy() {
let s = "Hello!".to_string();
let expected_len = s.len() as i32;
let block = ConcreteBlock::new(move || s.len() as i32);
assert!(invoke_int_block(&block) == expected_len);
assert_eq!(invoke_int_block(&block), expected_len);

let copied = block.copy();
assert!(invoke_int_block(&copied) == expected_len);
assert_eq!(invoke_int_block(&copied), expected_len);
}

#[test]
Expand All @@ -89,6 +89,6 @@ mod tests {
}

let block = make_block();
assert!(invoke_int_block(&block) == 7);
assert_eq!(invoke_int_block(&block), 7);
}
}

0 comments on commit 935383b

Please sign in to comment.