mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Fix application of modifications during 'ta add'
This commit is contained in:
parent
acd4aefc17
commit
2456012ed6
1 changed files with 33 additions and 3 deletions
|
@ -1,18 +1,24 @@
|
||||||
use crate::argparse::{DescriptionMod, Modification};
|
use crate::argparse::{DescriptionMod, Modification};
|
||||||
|
use crate::invocation::apply_modification;
|
||||||
use taskchampion::{Replica, Status};
|
use taskchampion::{Replica, Status};
|
||||||
use termcolor::WriteColor;
|
use termcolor::WriteColor;
|
||||||
|
|
||||||
pub(crate) fn execute<W: WriteColor>(
|
pub(crate) fn execute<W: WriteColor>(
|
||||||
w: &mut W,
|
w: &mut W,
|
||||||
replica: &mut Replica,
|
replica: &mut Replica,
|
||||||
modification: Modification,
|
mut modification: Modification,
|
||||||
) -> Result<(), crate::Error> {
|
) -> Result<(), crate::Error> {
|
||||||
|
// extract the description from the modification to handle it specially
|
||||||
let description = match modification.description {
|
let description = match modification.description {
|
||||||
DescriptionMod::Set(ref s) => s.clone(),
|
DescriptionMod::Set(ref s) => s.clone(),
|
||||||
_ => "(no description)".to_owned(),
|
_ => "(no description)".to_owned(),
|
||||||
};
|
};
|
||||||
let t = replica.new_task(Status::Pending, description).unwrap();
|
modification.description = DescriptionMod::None;
|
||||||
writeln!(w, "added task {}", t.get_uuid())?;
|
|
||||||
|
let task = replica.new_task(Status::Pending, description).unwrap();
|
||||||
|
let mut task = task.into_mut(replica);
|
||||||
|
apply_modification(&mut task, &modification)?;
|
||||||
|
writeln!(w, "added task {}", task.get_uuid())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,4 +49,28 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(w.into_string(), format!("added task {}\n", task.get_uuid()));
|
assert_eq!(w.into_string(), format!("added task {}\n", task.get_uuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_add_with_tags() {
|
||||||
|
let mut w = test_writer();
|
||||||
|
let mut replica = test_replica();
|
||||||
|
let modification = Modification {
|
||||||
|
description: DescriptionMod::Set(s!("my description")),
|
||||||
|
add_tags: vec![tag!("tag1")].drain(..).collect(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
execute(&mut w, &mut replica, modification).unwrap();
|
||||||
|
|
||||||
|
// check that the task appeared..
|
||||||
|
let working_set = replica.working_set().unwrap();
|
||||||
|
let task = replica
|
||||||
|
.get_task(working_set.by_index(1).unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(task.get_description(), "my description");
|
||||||
|
assert_eq!(task.get_status(), Status::Pending);
|
||||||
|
assert!(task.has_tag(&tag!("tag1")));
|
||||||
|
|
||||||
|
assert_eq!(w.into_string(), format!("added task {}\n", task.get_uuid()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue