add cstring eq

This commit is contained in:
bgkillas 2025-08-17 22:05:58 -04:00
parent 52cd62ab15
commit c93f6dfd82
2 changed files with 33 additions and 33 deletions

View file

@ -181,6 +181,35 @@ fn test_str() {
assert_eq!(WalletComponent::NAME, WalletComponent::C_NAME.to_string());
assert_eq!(WalletComponent::NAME, WalletComponent::STD_NAME.to_string());
}
#[test]
fn test_cstring() {
let a = CString::from_str("test");
let b = CString::from_str("test");
let c = CString::from_str("testb");
assert_eq!(a, b);
assert_ne!(a, c);
assert_ne!(c, a);
}
impl PartialEq for CString {
fn eq(&self, other: &Self) -> bool {
unsafe {
let mut ptra = self.0;
let mut ptrb = other.0;
let mut a = ptra.read();
let mut b = ptrb.read();
while a != 0 {
if a != b {
return false;
}
ptra = ptra.offset(1);
a = ptra.read();
ptrb = ptrb.offset(1);
b = ptrb.read();
}
b == 0
}
}
}
impl Display for CString {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.0.is_null() {

View file

@ -88,44 +88,15 @@ fn test_com_create() {
let ent = em.create();
{
em.create_component::<crate::noita::types::WalletComponent>(ent, id, cm);
println!(
"{:?}",
em.get_component_buffer::<crate::noita::types::WalletComponent>(cm)
);
em.create_component::<crate::noita::types::WalletComponent>(ent, id, cm);
println!(
"{:?}",
em.get_component_buffer::<crate::noita::types::WalletComponent>(cm)
);
em.create_component::<crate::noita::types::WalletComponent>(ent, id, cm);
println!(
"{:?}",
em.get_component_buffer::<crate::noita::types::WalletComponent>(cm)
);
em.create_component::<crate::noita::types::WalletComponent>(ent, id, cm);
println!(
"{:?}",
em.get_component_buffer::<crate::noita::types::WalletComponent>(cm)
);
}
let mut coms = em.iter_components::<crate::noita::types::WalletComponent>(ent.entry, cm);
println!(
"{:?}",
em.get_component_buffer::<crate::noita::types::WalletComponent>(cm)
.component_list
);
println!(
"{:?}",
em.get_component_buffer::<crate::noita::types::WalletComponent>(cm)
.component_list
.get(0)
);
println!("{:?}", coms.next());
println!("{:?}", coms.next());
println!("{:?}", coms.next());
println!("{:?}", coms.next());
println!("{:?}", coms.next());
println!("{:?}", coms.next());
assert_eq!(coms.next().unwrap().base.local_id, 0);
assert_eq!(coms.next().unwrap().base.local_id, 1);
assert_eq!(coms.next().unwrap().base.local_id, 2);
assert_eq!(coms.next().unwrap().base.local_id, 3);
}
#[repr(C)]
#[derive(Debug)]