Skip to content

Commit 935383b

Browse files
committed
Use assert_eq! instead of assert! where possible
1 parent 76f3956 commit 935383b

File tree

12 files changed

+61
-61
lines changed

12 files changed

+61
-61
lines changed

block2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct. For example, to create a block that adds two `i32`s, we could write:
4343
use block2::ConcreteBlock;
4444
let block = ConcreteBlock::new(|a: i32, b: i32| a + b);
4545
let block = block.copy();
46-
assert!(unsafe { block.call((5, 8)) } == 13);
46+
assert_eq!(unsafe { block.call((5, 8)) }, 13);
4747
```
4848

4949
It is important to copy your block to the heap (with the `copy` method) before

block2/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct. For example, to create a block that adds two `i32`s, we could write:
3636
# use block2::ConcreteBlock;
3737
let block = ConcreteBlock::new(|a: i32, b: i32| a + b);
3838
let block = block.copy();
39-
assert!(unsafe { block.call((5, 8)) } == 13);
39+
assert_eq!(unsafe { block.call((5, 8)) }, 13);
4040
```
4141
4242
It is important to copy your block to the heap (with the `copy` method) before

objc2-encode/src/encoding.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ mod tests {
198198
let i = Encoding::Int;
199199
let p = Encoding::Pointer(&Encoding::Int);
200200

201-
assert!(p == p);
202-
assert!(p != i);
201+
assert_eq!(p, p);
202+
assert_ne!(p, i);
203203
}
204204

205205
#[test]
@@ -213,8 +213,8 @@ mod tests {
213213
let i = Encoding::Int;
214214
let c = Encoding::Char;
215215

216-
assert!(i == i);
217-
assert!(i != c);
216+
assert_eq!(i, i);
217+
assert_ne!(i, c);
218218
}
219219

220220
#[test]
@@ -227,8 +227,8 @@ mod tests {
227227
#[test]
228228
fn test_struct_eq() {
229229
let s = Encoding::Struct("CGPoint", &[Encoding::Char, Encoding::Int]);
230-
assert!(s == s);
231-
assert!(s != Encoding::Int);
230+
assert_eq!(s, s);
231+
assert_ne!(s, Encoding::Int);
232232
}
233233

234234
#[test]
@@ -241,7 +241,7 @@ mod tests {
241241
#[test]
242242
fn test_union_eq() {
243243
let u = Encoding::Union("Onion", &[Encoding::Char, Encoding::Int]);
244-
assert!(u == u);
245-
assert!(u != Encoding::Int);
244+
assert_eq!(u, u);
245+
assert_ne!(u, Encoding::Int);
246246
}
247247
}

objc2-foundation/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ mod tests {
428428
fn test_iter() {
429429
let array = sample_array(4);
430430

431-
assert!(array.iter().count() == 4);
431+
assert_eq!(array.iter().count(), 4);
432432
assert!(array
433433
.iter()
434434
.enumerate()

objc2-foundation/src/enumerator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ impl<'a, C: INSFastEnumeration> NSFastEnumerator<'a, C> {
133133
if let Some(buf) = next_buf {
134134
// Check if the collection was mutated
135135
if let Some(mutations) = mutations {
136-
assert!(
137-
mutations == unsafe { *self.state.mutations_ptr },
136+
assert_eq!(
137+
mutations, unsafe { *self.state.mutations_ptr },
138138
"Mutation detected during enumeration of object {:p}",
139139
self.object
140140
);
@@ -178,7 +178,7 @@ mod tests {
178178
let array = NSArray::from_vec(vec);
179179

180180
let enumerator = array.iter();
181-
assert!(enumerator.count() == 4);
181+
assert_eq!(enumerator.count(), 4);
182182

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

192192
let enumerator = array.enumerator();
193-
assert!(enumerator.count() == 4);
193+
assert_eq!(enumerator.count(), 4);
194194

195195
let enumerator = array.enumerator();
196196
assert!(enumerator.enumerate().all(|(i, obj)| obj.get() == i as u32));

objc2/src/declare.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ impl ClassDecl {
181181
{
182182
let encs = F::Args::ENCODINGS;
183183
let sel_args = count_args(sel);
184-
assert!(
185-
sel_args == encs.len(),
184+
assert_eq!(
185+
sel_args,
186+
encs.len(),
186187
"Selector accepts {} arguments, but function accepts {}",
187188
sel_args,
188189
encs.len(),
@@ -217,8 +218,9 @@ impl ClassDecl {
217218
{
218219
let encs = F::Args::ENCODINGS;
219220
let sel_args = count_args(sel);
220-
assert!(
221-
sel_args == encs.len(),
221+
assert_eq!(
222+
sel_args,
223+
encs.len(),
222224
"Selector accepts {} arguments, but function accepts {}",
223225
sel_args,
224226
encs.len(),
@@ -319,8 +321,9 @@ impl ProtocolDecl {
319321
{
320322
let encs = Args::ENCODINGS;
321323
let sel_args = count_args(sel);
322-
assert!(
323-
sel_args == encs.len(),
324+
assert_eq!(
325+
sel_args,
326+
encs.len(),
324327
"Selector accepts {} arguments, but function accepts {}",
325328
sel_args,
326329
encs.len(),
@@ -380,19 +383,15 @@ mod tests {
380383
fn test_custom_class() {
381384
// Registering the custom class is in test_utils
382385
let obj = test_utils::custom_object();
383-
unsafe {
384-
let _: () = msg_send![obj, setFoo: 13u32];
385-
let result: u32 = msg_send![obj, foo];
386-
assert!(result == 13);
387-
}
386+
let _: () = unsafe { msg_send![obj, setFoo: 13u32] };
387+
let result: u32 = unsafe { msg_send![obj, foo] };
388+
assert_eq!(result, 13);
388389
}
389390

390391
#[test]
391392
fn test_class_method() {
392393
let cls = test_utils::custom_class();
393-
unsafe {
394-
let result: u32 = msg_send![cls, classFoo];
395-
assert!(result == 7);
396-
}
394+
let result: u32 = unsafe { msg_send![cls, classFoo] };
395+
assert_eq!(result, 7);
397396
}
398397
}

objc2/src/message/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ mod tests {
362362
let _: () = msg_send![obj, setFoo: 4u32];
363363
msg_send![obj, foo]
364364
};
365-
assert!(result == 4);
365+
assert_eq!(result, 4);
366366
}
367367

368368
#[test]
@@ -375,7 +375,7 @@ mod tests {
375375
c: 3,
376376
d: 4,
377377
};
378-
assert!(result == expected);
378+
assert_eq!(result, expected);
379379
}
380380

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

416416
// The subclass is overriden to return foo + 2
417417
let foo: u32 = msg_send![obj, foo];
418-
assert!(foo == 6);
418+
assert_eq!(foo, 6);
419419
}
420420
}
421421

objc2/src/rc/id.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,16 @@ mod tests {
460460
let obj: *mut Object = msg_send![obj, init];
461461
Id::new(NonNull::new_unchecked(obj))
462462
};
463-
assert!(retain_count(&obj) == 1);
463+
assert_eq!(retain_count(&obj), 1);
464464

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

468468
let cloned = obj.clone();
469-
assert!(retain_count(&cloned) == 2);
470-
assert!(retain_count(&obj) == 2);
469+
assert_eq!(retain_count(&cloned), 2);
470+
assert_eq!(retain_count(&obj), 2);
471471

472472
drop(obj);
473-
assert!(retain_count(&cloned) == 1);
473+
assert_eq!(retain_count(&cloned), 1);
474474
}
475475
}

objc2/src/runtime.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ mod tests {
547547
fn test_ivar() {
548548
let cls = test_utils::custom_class();
549549
let ivar = cls.instance_variable("_foo").unwrap();
550-
assert!(ivar.name() == "_foo");
550+
assert_eq!(ivar.name(), "_foo");
551551
assert!(ivar.type_encoding() == &<u32>::ENCODING);
552552
assert!(ivar.offset() > 0);
553553

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

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

579-
assert!(Class::get(cls.name()) == Some(cls));
579+
assert_eq!(Class::get(cls.name()), Some(cls));
580580

581581
let metaclass = cls.metaclass();
582582
// The metaclass of a root class is a subclass of the root class
583-
assert!(metaclass.superclass().unwrap() == cls);
583+
assert_eq!(metaclass.superclass().unwrap(), cls);
584584

585585
let subclass = test_utils::custom_subclass();
586-
assert!(subclass.superclass().unwrap() == cls);
586+
assert_eq!(subclass.superclass().unwrap(), cls);
587587
}
588588

589589
#[test]
@@ -596,7 +596,7 @@ mod tests {
596596
#[test]
597597
fn test_protocol() {
598598
let proto = test_utils::custom_protocol();
599-
assert!(proto.name() == "CustomProtocol");
599+
assert_eq!(proto.name(), "CustomProtocol");
600600
let class = test_utils::custom_class();
601601
assert!(class.conforms_to(proto));
602602
let class_protocols = class.adopted_protocols();
@@ -631,12 +631,12 @@ mod tests {
631631
#[test]
632632
fn test_object() {
633633
let mut obj = test_utils::custom_object();
634-
assert!(obj.class() == test_utils::custom_class());
634+
assert_eq!(obj.class(), test_utils::custom_class());
635635
let result: u32 = unsafe {
636636
obj.set_ivar("_foo", 4u32);
637637
*obj.get_ivar("_foo")
638638
};
639-
assert!(result == 4);
639+
assert_eq!(result, 4);
640640
}
641641

642642
#[test]

objc2/src/test_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::declare::{ClassDecl, ProtocolDecl};
66
use crate::runtime::{Class, Object, Protocol, Sel};
77
use crate::{ffi, Encode, Encoding, MessageReceiver};
88

9+
#[derive(Debug)]
910
pub(crate) struct CustomObject {
1011
obj: *mut Object,
1112
}
@@ -51,7 +52,7 @@ impl Drop for CustomObject {
5152
}
5253
}
5354

54-
#[derive(Eq, PartialEq)]
55+
#[derive(Debug, Eq, PartialEq)]
5556
#[repr(C)]
5657
pub(crate) struct CustomStruct {
5758
pub(crate) a: u64,

0 commit comments

Comments
 (0)