mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
use a s!(..) shorthand in CLI tests
This commit is contained in:
parent
7e906ced22
commit
922e71cd4d
12 changed files with 65 additions and 69 deletions
|
@ -197,27 +197,27 @@ mod test {
|
|||
fn test_id_list_uuids() {
|
||||
assert_eq!(
|
||||
id_list("12341234").unwrap().1,
|
||||
vec![TaskId::PartialUuid("12341234".to_owned())]
|
||||
vec![TaskId::PartialUuid(s!("12341234"))]
|
||||
);
|
||||
assert_eq!(
|
||||
id_list("1234abcd").unwrap().1,
|
||||
vec![TaskId::PartialUuid("1234abcd".to_owned())]
|
||||
vec![TaskId::PartialUuid(s!("1234abcd"))]
|
||||
);
|
||||
assert_eq!(
|
||||
id_list("abcd1234").unwrap().1,
|
||||
vec![TaskId::PartialUuid("abcd1234".to_owned())]
|
||||
vec![TaskId::PartialUuid(s!("abcd1234"))]
|
||||
);
|
||||
assert_eq!(
|
||||
id_list("abcd1234-1234").unwrap().1,
|
||||
vec![TaskId::PartialUuid("abcd1234-1234".to_owned())]
|
||||
vec![TaskId::PartialUuid(s!("abcd1234-1234"))]
|
||||
);
|
||||
assert_eq!(
|
||||
id_list("abcd1234-1234-2345").unwrap().1,
|
||||
vec![TaskId::PartialUuid("abcd1234-1234-2345".to_owned())]
|
||||
vec![TaskId::PartialUuid(s!("abcd1234-1234-2345"))]
|
||||
);
|
||||
assert_eq!(
|
||||
id_list("abcd1234-1234-2345-3456").unwrap().1,
|
||||
vec![TaskId::PartialUuid("abcd1234-1234-2345-3456".to_owned())]
|
||||
vec![TaskId::PartialUuid(s!("abcd1234-1234-2345-3456"))]
|
||||
);
|
||||
assert_eq!(
|
||||
id_list("abcd1234-1234-2345-3456-0123456789ab").unwrap().1,
|
||||
|
@ -241,10 +241,10 @@ mod test {
|
|||
#[test]
|
||||
fn test_id_list_uuids_mixed() {
|
||||
assert_eq!(id_list("abcd1234,abcd1234-1234,abcd1234-1234-2345,abcd1234-1234-2345-3456,abcd1234-1234-2345-3456-0123456789ab").unwrap().1,
|
||||
vec![TaskId::PartialUuid("abcd1234".to_owned()),
|
||||
TaskId::PartialUuid("abcd1234-1234".to_owned()),
|
||||
TaskId::PartialUuid("abcd1234-1234-2345".to_owned()),
|
||||
TaskId::PartialUuid("abcd1234-1234-2345-3456".to_owned()),
|
||||
vec![TaskId::PartialUuid(s!("abcd1234")),
|
||||
TaskId::PartialUuid(s!("abcd1234-1234")),
|
||||
TaskId::PartialUuid(s!("abcd1234-1234-2345")),
|
||||
TaskId::PartialUuid(s!("abcd1234-1234-2345-3456")),
|
||||
TaskId::Uuid(Uuid::parse_str("abcd1234-1234-2345-3456-0123456789ab").unwrap()),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ mod test {
|
|||
Command::from_argv(argv!["task", "version"]).unwrap(),
|
||||
Command {
|
||||
subcommand: Subcommand::Version,
|
||||
command_name: "task".to_owned(),
|
||||
command_name: s!("task"),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ mod test {
|
|||
Filter {
|
||||
universe: Universe::IdList(vec![
|
||||
TaskId::WorkingSetId(1),
|
||||
TaskId::PartialUuid("abcd1234".to_owned()),
|
||||
TaskId::PartialUuid(s!("abcd1234")),
|
||||
]),
|
||||
..Default::default()
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ mod test {
|
|||
assert_eq!(
|
||||
modification,
|
||||
Modification {
|
||||
description: DescriptionMod::Set("newdesc".to_owned()),
|
||||
description: DescriptionMod::Set(s!("newdesc")),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
|
@ -168,7 +168,7 @@ mod test {
|
|||
assert_eq!(
|
||||
modification,
|
||||
Modification {
|
||||
add_tags: set!["abc".to_owned(), "def".to_owned()],
|
||||
add_tags: set![s!("abc"), s!("def")],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
|
@ -181,7 +181,7 @@ mod test {
|
|||
assert_eq!(
|
||||
modification,
|
||||
Modification {
|
||||
description: DescriptionMod::Set("new desc fun".to_owned()),
|
||||
description: DescriptionMod::Set(s!("new desc fun")),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
|
@ -195,9 +195,9 @@ mod test {
|
|||
assert_eq!(
|
||||
modification,
|
||||
Modification {
|
||||
description: DescriptionMod::Set("new desc fun".to_owned()),
|
||||
add_tags: set!["next".to_owned()],
|
||||
remove_tags: set!["daytime".to_owned()],
|
||||
description: DescriptionMod::Set(s!("new desc fun")),
|
||||
add_tags: set![s!("next")],
|
||||
remove_tags: set![s!("daytime")],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
|
|
|
@ -409,7 +409,7 @@ mod test {
|
|||
fn test_add_description() {
|
||||
let subcommand = Subcommand::Add {
|
||||
modification: Modification {
|
||||
description: DescriptionMod::Set("foo".to_owned()),
|
||||
description: DescriptionMod::Set(s!("foo")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
@ -423,7 +423,7 @@ mod test {
|
|||
fn test_add_description_multi() {
|
||||
let subcommand = Subcommand::Add {
|
||||
modification: Modification {
|
||||
description: DescriptionMod::Set("foo bar".to_owned()),
|
||||
description: DescriptionMod::Set(s!("foo bar")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
@ -441,7 +441,7 @@ mod test {
|
|||
..Default::default()
|
||||
},
|
||||
modification: Modification {
|
||||
description: DescriptionMod::Set("foo bar".to_owned()),
|
||||
description: DescriptionMod::Set(s!("foo bar")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
@ -459,7 +459,7 @@ mod test {
|
|||
..Default::default()
|
||||
},
|
||||
modification: Modification {
|
||||
description: DescriptionMod::Append("foo bar".to_owned()),
|
||||
description: DescriptionMod::Append(s!("foo bar")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
@ -477,7 +477,7 @@ mod test {
|
|||
..Default::default()
|
||||
},
|
||||
modification: Modification {
|
||||
description: DescriptionMod::Prepend("foo bar".to_owned()),
|
||||
description: DescriptionMod::Prepend(s!("foo bar")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
@ -513,7 +513,7 @@ mod test {
|
|||
..Default::default()
|
||||
},
|
||||
modification: Modification {
|
||||
description: DescriptionMod::Set("now-finished".to_owned()),
|
||||
description: DescriptionMod::Set(s!("now-finished")),
|
||||
status: Some(Status::Completed),
|
||||
..Default::default()
|
||||
},
|
||||
|
@ -551,7 +551,7 @@ mod test {
|
|||
},
|
||||
modification: Modification {
|
||||
active: Some(true),
|
||||
description: DescriptionMod::Set("mod".to_owned()),
|
||||
description: DescriptionMod::Set(s!("mod")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
@ -587,7 +587,7 @@ mod test {
|
|||
..Default::default()
|
||||
},
|
||||
modification: Modification {
|
||||
description: DescriptionMod::Set("mod".to_owned()),
|
||||
description: DescriptionMod::Set(s!("mod")),
|
||||
active: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
|
|
|
@ -27,7 +27,7 @@ mod test {
|
|||
let mut w = test_writer();
|
||||
let mut replica = test_replica();
|
||||
let modification = Modification {
|
||||
description: DescriptionMod::Set("my description".to_owned()),
|
||||
description: DescriptionMod::Set(s!("my description")),
|
||||
..Default::default()
|
||||
};
|
||||
execute(&mut w, &mut replica, modification).unwrap();
|
||||
|
|
|
@ -20,12 +20,12 @@ mod test {
|
|||
#[test]
|
||||
fn test_summary() {
|
||||
let mut w = test_writer();
|
||||
execute(&mut w, "task".to_owned(), true).unwrap();
|
||||
execute(&mut w, s!("task"), true).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_long() {
|
||||
let mut w = test_writer();
|
||||
execute(&mut w, "task".to_owned(), false).unwrap();
|
||||
execute(&mut w, s!("task"), false).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,9 +52,7 @@ mod test {
|
|||
fn test_info() {
|
||||
let mut w = test_writer();
|
||||
let mut replica = test_replica();
|
||||
replica
|
||||
.new_task(Status::Pending, "my task".to_owned())
|
||||
.unwrap();
|
||||
replica.new_task(Status::Pending, s!("my task")).unwrap();
|
||||
|
||||
let filter = Filter {
|
||||
..Default::default()
|
||||
|
|
|
@ -41,9 +41,7 @@ mod test {
|
|||
fn test_list() {
|
||||
let mut w = test_writer();
|
||||
let mut replica = test_replica();
|
||||
replica
|
||||
.new_task(Status::Pending, "my task".to_owned())
|
||||
.unwrap();
|
||||
replica.new_task(Status::Pending, s!("my task")).unwrap();
|
||||
|
||||
let report = Report {
|
||||
filter: Filter {
|
||||
|
|
|
@ -33,14 +33,14 @@ mod test {
|
|||
let mut replica = test_replica();
|
||||
|
||||
let task = replica
|
||||
.new_task(Status::Pending, "old description".to_owned())
|
||||
.new_task(Status::Pending, s!("old description"))
|
||||
.unwrap();
|
||||
|
||||
let filter = Filter {
|
||||
..Default::default()
|
||||
};
|
||||
let modification = Modification {
|
||||
description: DescriptionMod::Set("new description".to_owned()),
|
||||
description: DescriptionMod::Set(s!("new description")),
|
||||
..Default::default()
|
||||
};
|
||||
execute(&mut w, &mut replica, filter, modification).unwrap();
|
||||
|
|
|
@ -124,9 +124,9 @@ mod test {
|
|||
fn exact_ids() {
|
||||
let mut replica = test_replica();
|
||||
|
||||
let t1 = replica.new_task(Status::Pending, "A".to_owned()).unwrap();
|
||||
let t2 = replica.new_task(Status::Completed, "B".to_owned()).unwrap();
|
||||
let _t = replica.new_task(Status::Pending, "C".to_owned()).unwrap();
|
||||
let t1 = replica.new_task(Status::Pending, s!("A")).unwrap();
|
||||
let t2 = replica.new_task(Status::Completed, s!("B")).unwrap();
|
||||
let _t = replica.new_task(Status::Pending, s!("C")).unwrap();
|
||||
replica.gc().unwrap();
|
||||
|
||||
let t1uuid = *t1.get_uuid();
|
||||
|
@ -144,16 +144,16 @@ mod test {
|
|||
.map(|t| t.get_description().to_owned())
|
||||
.collect();
|
||||
filtered.sort();
|
||||
assert_eq!(vec!["A".to_owned(), "B".to_owned()], filtered);
|
||||
assert_eq!(vec![s!("A"), s!("B")], filtered);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_ids() {
|
||||
let mut replica = test_replica();
|
||||
|
||||
let t1 = replica.new_task(Status::Pending, "A".to_owned()).unwrap();
|
||||
let t2 = replica.new_task(Status::Completed, "B".to_owned()).unwrap();
|
||||
let _t = replica.new_task(Status::Pending, "C".to_owned()).unwrap();
|
||||
let t1 = replica.new_task(Status::Pending, s!("A")).unwrap();
|
||||
let t2 = replica.new_task(Status::Completed, s!("B")).unwrap();
|
||||
let _t = replica.new_task(Status::Pending, s!("C")).unwrap();
|
||||
replica.gc().unwrap();
|
||||
|
||||
let t1uuid = *t1.get_uuid();
|
||||
|
@ -173,16 +173,16 @@ mod test {
|
|||
.map(|t| t.get_description().to_owned())
|
||||
.collect();
|
||||
filtered.sort();
|
||||
assert_eq!(vec!["A".to_owned(), "B".to_owned()], filtered);
|
||||
assert_eq!(vec![s!("A"), s!("B")], filtered);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_tasks() {
|
||||
let mut replica = test_replica();
|
||||
|
||||
replica.new_task(Status::Pending, "A".to_owned()).unwrap();
|
||||
replica.new_task(Status::Completed, "B".to_owned()).unwrap();
|
||||
replica.new_task(Status::Deleted, "C".to_owned()).unwrap();
|
||||
replica.new_task(Status::Pending, s!("A")).unwrap();
|
||||
replica.new_task(Status::Completed, s!("B")).unwrap();
|
||||
replica.new_task(Status::Deleted, s!("C")).unwrap();
|
||||
replica.gc().unwrap();
|
||||
|
||||
let filter = Filter {
|
||||
|
@ -194,10 +194,7 @@ mod test {
|
|||
.map(|t| t.get_description().to_owned())
|
||||
.collect();
|
||||
filtered.sort();
|
||||
assert_eq!(
|
||||
vec!["A".to_owned(), "B".to_owned(), "C".to_owned()],
|
||||
filtered
|
||||
);
|
||||
assert_eq!(vec![s!("A"), s!("B"), s!("C")], filtered);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -207,57 +204,54 @@ mod test {
|
|||
let no: Tag = "no".try_into()?;
|
||||
|
||||
let mut t1 = replica
|
||||
.new_task(Status::Pending, "A".to_owned())?
|
||||
.new_task(Status::Pending, s!("A"))?
|
||||
.into_mut(&mut replica);
|
||||
t1.add_tag(&yes)?;
|
||||
let mut t2 = replica
|
||||
.new_task(Status::Pending, "B".to_owned())?
|
||||
.new_task(Status::Pending, s!("B"))?
|
||||
.into_mut(&mut replica);
|
||||
t2.add_tag(&yes)?;
|
||||
t2.add_tag(&no)?;
|
||||
let mut t3 = replica
|
||||
.new_task(Status::Pending, "C".to_owned())?
|
||||
.new_task(Status::Pending, s!("C"))?
|
||||
.into_mut(&mut replica);
|
||||
t3.add_tag(&no)?;
|
||||
let _t4 = replica.new_task(Status::Pending, "D".to_owned())?;
|
||||
let _t4 = replica.new_task(Status::Pending, s!("D"))?;
|
||||
|
||||
// look for just "yes" (A and B)
|
||||
let filter = Filter {
|
||||
universe: Universe::AllTasks,
|
||||
conditions: vec![Condition::HasTag("yes".to_owned())],
|
||||
conditions: vec![Condition::HasTag(s!("yes"))],
|
||||
..Default::default()
|
||||
};
|
||||
let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter)?
|
||||
.map(|t| t.get_description().to_owned())
|
||||
.collect();
|
||||
filtered.sort();
|
||||
assert_eq!(vec!["A".to_owned(), "B".to_owned()], filtered);
|
||||
assert_eq!(vec![s!("A"), s!("B")], filtered);
|
||||
|
||||
// look for tags without "no" (A, D)
|
||||
let filter = Filter {
|
||||
universe: Universe::AllTasks,
|
||||
conditions: vec![Condition::NoTag("no".to_owned())],
|
||||
conditions: vec![Condition::NoTag(s!("no"))],
|
||||
..Default::default()
|
||||
};
|
||||
let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter)?
|
||||
.map(|t| t.get_description().to_owned())
|
||||
.collect();
|
||||
filtered.sort();
|
||||
assert_eq!(vec!["A".to_owned(), "D".to_owned()], filtered);
|
||||
assert_eq!(vec![s!("A"), s!("D")], filtered);
|
||||
|
||||
// look for tags with "yes" and "no" (B)
|
||||
let filter = Filter {
|
||||
universe: Universe::AllTasks,
|
||||
conditions: vec![
|
||||
Condition::HasTag("yes".to_owned()),
|
||||
Condition::HasTag("no".to_owned()),
|
||||
],
|
||||
conditions: vec![Condition::HasTag(s!("yes")), Condition::HasTag(s!("no"))],
|
||||
..Default::default()
|
||||
};
|
||||
let filtered: Vec<_> = filtered_tasks(&mut replica, &filter)?
|
||||
.map(|t| t.get_description().to_owned())
|
||||
.collect();
|
||||
assert_eq!(vec!["B".to_owned()], filtered);
|
||||
assert_eq!(vec![s!("B")], filtered);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -266,9 +260,9 @@ mod test {
|
|||
fn pending_tasks() {
|
||||
let mut replica = test_replica();
|
||||
|
||||
replica.new_task(Status::Pending, "A".to_owned()).unwrap();
|
||||
replica.new_task(Status::Completed, "B".to_owned()).unwrap();
|
||||
replica.new_task(Status::Deleted, "C".to_owned()).unwrap();
|
||||
replica.new_task(Status::Pending, s!("A")).unwrap();
|
||||
replica.new_task(Status::Completed, s!("B")).unwrap();
|
||||
replica.new_task(Status::Deleted, s!("C")).unwrap();
|
||||
replica.gc().unwrap();
|
||||
|
||||
let filter = Filter {
|
||||
|
@ -280,6 +274,6 @@ mod test {
|
|||
.map(|t| t.get_description().to_owned())
|
||||
.collect();
|
||||
filtered.sort();
|
||||
assert_eq!(vec!["A".to_owned()], filtered);
|
||||
assert_eq!(vec![s!("A")], filtered);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,3 +24,9 @@ macro_rules! set(
|
|||
}
|
||||
};
|
||||
);
|
||||
|
||||
/// Create a String from an &str; just a testing shorthand
|
||||
#[cfg(test)]
|
||||
macro_rules! s(
|
||||
{ $s:expr } => { $s.to_owned() };
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue