mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
add cstring eq
This commit is contained in:
parent
52cd62ab15
commit
c93f6dfd82
2 changed files with 33 additions and 33 deletions
|
@ -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() {
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue