mirror of
https://github.com/archtechx/todo-system.git
synced 2025-12-12 09:04:03 +00:00
support scanning todo!() Rust macros
This commit is contained in:
parent
a9a6a66b96
commit
b4a74cb633
2 changed files with 70 additions and 0 deletions
7
samples/2.rs
Normal file
7
samples/2.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn foo() {
|
||||||
|
// Rust TODOs can only be generic
|
||||||
|
todo!("generic");
|
||||||
|
todo!();
|
||||||
|
todo!("@foo not category");
|
||||||
|
todo!("00 not priority");
|
||||||
|
}
|
||||||
63
src/scan.rs
63
src/scan.rs
|
|
@ -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 {
|
fn clean_line<'a>(line: &'a str, delimiter_word: &str) -> &'a str {
|
||||||
return line.split_once(delimiter_word).unwrap().1
|
return line.split_once(delimiter_word).unwrap().1
|
||||||
.trim()
|
.trim()
|
||||||
|
|
@ -154,6 +155,19 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
|
||||||
|
|
||||||
let text = clean_line(line, word);
|
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:`
|
// Handles: `todo`, `TODO`, `todo:`, `TODO:`
|
||||||
// Also trims `"` and `'` to handle cases like `foo="bar 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" {
|
if word.to_lowercase().trim_end_matches(':').trim_end_matches('"').trim_end_matches('\'') == "todo" {
|
||||||
|
|
@ -773,6 +787,55 @@ mod tests {
|
||||||
}, entries[9]);
|
}, 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]
|
#[test]
|
||||||
fn todo_file_test() {
|
fn todo_file_test() {
|
||||||
let mut entries: Vec<Entry> = vec![];
|
let mut entries: Vec<Entry> = vec![];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue