1
0
Fork 0
mirror of https://github.com/archtechx/todo-system.git synced 2025-12-12 17:14:03 +00:00

support scanning todo!() Rust macros

This commit is contained in:
Samuel Štancl 2023-12-11 11:09:02 +01:00
parent a9a6a66b96
commit b4a74cb633
2 changed files with 70 additions and 0 deletions

View file

@ -89,6 +89,7 @@ fn parse_priority(word: &str) -> Option<isize> {
}
}
/// Remove closing tags, comments, and whitespace
fn clean_line<'a>(line: &'a str, delimiter_word: &str) -> &'a str {
return line.split_once(delimiter_word).unwrap().1
.trim()
@ -154,6 +155,19 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
let text = clean_line(line, word);
if word.starts_with("todo!(") {
entries.push(Entry {
text: line.trim().to_string(),
location: Location {
file: filename.clone(),
line: line_num + 1,
},
data: EntryData::Generic,
});
break;
}
// Handles: `todo`, `TODO`, `todo:`, `TODO:`
// Also trims `"` and `'` to handle cases like `foo="bar todo"`
if word.to_lowercase().trim_end_matches(':').trim_end_matches('"').trim_end_matches('\'') == "todo" {
@ -773,6 +787,55 @@ mod tests {
}, entries[9]);
}
#[test]
fn sample_test_rs() {
let mut entries: Vec<Entry> = vec![];
let mut path = std::env::current_dir().unwrap();
path.push("samples");
path.push("2.rs");
scan_file(path.as_path(), &mut entries).unwrap();
assert_eq!(4, entries.len());
assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("todo!(\"generic\");"),
location: Location {
file: path.clone(),
line: 3,
}
}, entries[0]);
assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("todo!();"),
location: Location {
file: path.clone(),
line: 4,
}
}, entries[1]);
assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("todo!(\"@foo not category\");"),
location: Location {
file: path.clone(),
line: 5,
}
}, entries[2]);
assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("todo!(\"00 not priority\");"),
location: Location {
file: path.clone(),
line: 6,
}
}, entries[3]);
}
#[test]
fn todo_file_test() {
let mut entries: Vec<Entry> = vec![];