Compare commits

...

5 Commits

Author SHA1 Message Date
Bel LaPointe b0b962277a a todo 2025-11-11 19:51:11 -07:00
Bel LaPointe 65bc42c246 vim 2025-11-11 19:49:13 -07:00
Bel LaPointe bef9ef1a2a ooo tests pass 2025-11-11 19:34:00 -07:00
Bel LaPointe 5bfd9e52c3 some test edit 2025-11-11 19:24:21 -07:00
Bel LaPointe 2076ebd6f4 some test edit 2025-11-11 19:22:19 -07:00
3 changed files with 87 additions and 8 deletions

View File

@ -0,0 +1 @@
{"ts":1762915830,"patch":{"op":"add","path":"/0","value":"scheduled tasks hide"}}

View File

@ -39,12 +39,6 @@ fn main() {
if flags.edit {
edit::files(&files);
for file in files.files.iter() {
file.persist_stage()
.expect("failed to persist edited stage to log file");
file.stage_persisted()
.expect("failed to stage edits from log files");
}
}
}
@ -576,12 +570,28 @@ mod tests {
pub fn file_contains(d: &tempdir::TempDir, fname: &str, content: &str) {
let p = d.path().join(&fname);
let file_content = file_content(&p.to_str().unwrap().to_string());
assert!(file_content.contains(content));
assert!(
file_content.contains(content),
"expected {:?} but got {:?}",
content,
file_content
);
}
pub fn file_content(p: &String) -> String {
std::fs::read_to_string(p).unwrap()
}
pub fn list_dir(d: &tempdir::TempDir) -> Vec<String> {
std::fs::read_dir(d)
.unwrap()
.filter(|x| x.is_ok())
.map(|x| x.unwrap())
.filter(|x| x.metadata().unwrap().is_file())
.map(|x| x.path().display().to_string())
.filter(|x| !x.contains("/."))
.collect()
}
}
mod edit {
@ -604,7 +614,19 @@ mod edit {
}
fn edit_dir(d: &tempdir::TempDir) -> Result<(), String> {
panic!("not impl");
let mut cmd = std::process::Command::new("vim");
cmd.stdout(std::process::Stdio::inherit());
cmd.stdin(std::process::Stdio::inherit());
cmd.stderr(std::process::Stdio::inherit());
cmd.arg("-p");
for f in tests::list_dir(&d).iter() {
cmd.arg(Events::basename(f));
}
cmd.current_dir(d.path().display().to_string());
match cmd.output() {
Ok(_) => Ok(()),
Err(msg) => Err(format!("failed to vim: {}", msg)),
}
}
fn persist_edits(d: &tempdir::TempDir, files: &Files) -> Result<(), String> {
@ -616,8 +638,62 @@ mod edit {
let before = file.stage()?;
let after = new_files.files[i].stage()?;
file.persist_delta(before, after)?;
file.stage_persisted()?;
}
Ok(())
}
#[cfg(test)]
mod test_edit {
use super::*;
#[test]
fn test_build_empty() {
tests::with_dir(|d| {
build_dir(&d, &Files { files: vec![] }).expect("failed to build empty dir");
});
}
#[test]
fn test_build_with_files() {
tests::with_dir(|d1| {
tests::write_file(&d1, "file_a", "hello world a");
tests::write_file(&d1, "file_b", "hello world b");
let p1 = d1.path().join("file_a").display().to_string();
let p2 = d1.path().join("file_b").display().to_string();
let files = Files::new(&vec![p1, p2]);
tests::with_dir(|d2| {
build_dir(&d2, &files).expect("failed to build non-empty dir");
tests::file_contains(&d2, "file_a", "hello world a");
tests::file_contains(&d2, "file_b", "hello world b");
});
});
}
#[test]
fn test_persist_edits_with_files() {
let hostname = gethostname::gethostname().into_string().unwrap();
let log_file = format!(".file.{}", hostname);
let log_file = log_file.as_str();
tests::with_dir(|d1| {
tests::write_file(&d1, "file", "- foo");
let p = d1.path().join("file").display().to_string();
let files = Files::new(&vec![p]);
files.files[0].persist_stage().expect("failed to init log");
tests::file_contains(&d1, log_file, r#""foo""#);
tests::with_dir(|d2| {
build_dir(&d2, &files).expect("failed to build dir");
tests::file_contains(&d2, "file", "- foo");
tests::write_file(&d2, "file", "- foobar\n- bar");
persist_edits(&d2, &files).expect("failed to persist edits");
tests::file_contains(&d1, "file", "- foobar\n- bar");
tests::file_contains(&d1, log_file, r#""foo""#);
tests::file_contains(&d1, log_file, r#""foobar""#);
tests::file_contains(&d1, log_file, r#""bar""#);
});
});
}
}
}

2
pttodoest/todo.yaml Normal file
View File

@ -0,0 +1,2 @@
- scheduled tasks hide