diff options
Diffstat (limited to 'lib/xixanta/src/node.rs')
| -rw-r--r-- | lib/xixanta/src/node.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs index 7cfc107..465dde2 100644 --- a/lib/xixanta/src/node.rs +++ b/lib/xixanta/src/node.rs @@ -1,5 +1,13 @@ use std::fmt; +/// Returns true if this String follows the naming +/// conventions as expected by the address sanitizer. +pub fn is_asan_friendly_name(string: &str) -> bool { + let name = string.split("::").last().unwrap_or(""); + + name.starts_with("zp_") || name.starts_with("wr_") || name.starts_with("m_") +} + /// A Positioned String. That is, a String which also has information on the /// line number and the column range. #[derive(Debug, Default, Clone, PartialEq)] @@ -456,3 +464,25 @@ impl PNode { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn is_asan_friendly_name_test() { + let tests = vec![ + ("zp_name", true), + ("name", false), + ("Scope::zp_name", true), + ("Scope::Inner::zp_good", true), + ("Scope::Inner::bad", false), + ]; + + for (name, expect) in tests { + let string = String::from(name); + + assert_eq!(is_asan_friendly_name(&string), expect); + } + } +} |
