I recently read chapter 12 of the book and decided to create my own implementation of the program, my program is a shell over the aho_corasick crate, which stores, updates and saves data from the search file in it. In my unit test for the AhoCorasickBuilder getter, I encountered a problem because AhoCorasickBuilder does not implement PartialEq. ChatGPT advised me to convert to "raw pointer"(*const _), whether it is correct to write such unit tests for the getter.:
#[test]
fn get_builder(){
let mut builder=AhoCorasickBuilder::new();
builder.auto_configure(&["some", "hay"]);
let grep = MiniGrep::new(["some", "hay"], "some haystack", None);
assert_eq!(grep.get_builder() as *const _,&grep.corasick_builder as *const _);
}
or
#[test]
fn get_mut_matches(){
let mut grep = MiniGrep::new(["some", "hay"], "some haystack", None);
assert_eq!(grep.get_mut_matches() as *const _,&mut grep.matches as *const _)
}
And how is it better to write like that?:
#[test]
fn get_matches(){
let grep = MiniGrep::new(["some", "hay"], "some haystack", None);
assert_eq!(&grep.matches,grep.get_matches())
}
or:
#[test]
fn get_matches(){
let grep = MiniGrep::new(["some", "hay"], "some haystack", None);
assert_eq!(grep.matches.as_slice() as *const _ ,grep.get_matches() as *const _)
}