fix comment and add basic unit test
This commit is contained in:
parent
b8a96d81f8
commit
1d15a207bb
@ -41,7 +41,7 @@ impl NoteField {
|
||||
if self.name.contains(bad_chars) {
|
||||
self.name = self.name.replace(bad_chars, "");
|
||||
}
|
||||
// and leading/trailing whitespace
|
||||
// and leading/trailing whitespace and special chars
|
||||
let bad_start_chars = |c: char| c == '#' || c == '/' || c == '^' || c.is_whitespace();
|
||||
let trimmed = self.name.trim().trim_start_matches(bad_start_chars);
|
||||
if trimmed.len() != self.name.len() {
|
||||
@ -49,3 +49,20 @@ impl NoteField {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn name() {
|
||||
let mut field = NoteField {
|
||||
ord: None,
|
||||
name: String::new(),
|
||||
config: NoteFieldConfig::default(),
|
||||
};
|
||||
field.name = " # / te{st} ".into();
|
||||
field.fix_name();
|
||||
assert_eq!(&field.name, "test");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user