use a s!(..) shorthand in CLI tests

This commit is contained in:
Dustin J. Mitchell 2020-12-24 21:14:20 +00:00
parent 7e906ced22
commit 922e71cd4d
12 changed files with 65 additions and 69 deletions

View file

@ -197,27 +197,27 @@ mod test {
fn test_id_list_uuids() { fn test_id_list_uuids() {
assert_eq!( assert_eq!(
id_list("12341234").unwrap().1, id_list("12341234").unwrap().1,
vec![TaskId::PartialUuid("12341234".to_owned())] vec![TaskId::PartialUuid(s!("12341234"))]
); );
assert_eq!( assert_eq!(
id_list("1234abcd").unwrap().1, id_list("1234abcd").unwrap().1,
vec![TaskId::PartialUuid("1234abcd".to_owned())] vec![TaskId::PartialUuid(s!("1234abcd"))]
); );
assert_eq!( assert_eq!(
id_list("abcd1234").unwrap().1, id_list("abcd1234").unwrap().1,
vec![TaskId::PartialUuid("abcd1234".to_owned())] vec![TaskId::PartialUuid(s!("abcd1234"))]
); );
assert_eq!( assert_eq!(
id_list("abcd1234-1234").unwrap().1, id_list("abcd1234-1234").unwrap().1,
vec![TaskId::PartialUuid("abcd1234-1234".to_owned())] vec![TaskId::PartialUuid(s!("abcd1234-1234"))]
); );
assert_eq!( assert_eq!(
id_list("abcd1234-1234-2345").unwrap().1, id_list("abcd1234-1234-2345").unwrap().1,
vec![TaskId::PartialUuid("abcd1234-1234-2345".to_owned())] vec![TaskId::PartialUuid(s!("abcd1234-1234-2345"))]
); );
assert_eq!( assert_eq!(
id_list("abcd1234-1234-2345-3456").unwrap().1, 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!( assert_eq!(
id_list("abcd1234-1234-2345-3456-0123456789ab").unwrap().1, id_list("abcd1234-1234-2345-3456-0123456789ab").unwrap().1,
@ -241,10 +241,10 @@ mod test {
#[test] #[test]
fn test_id_list_uuids_mixed() { 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, 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()), vec![TaskId::PartialUuid(s!("abcd1234")),
TaskId::PartialUuid("abcd1234-1234".to_owned()), TaskId::PartialUuid(s!("abcd1234-1234")),
TaskId::PartialUuid("abcd1234-1234-2345".to_owned()), TaskId::PartialUuid(s!("abcd1234-1234-2345")),
TaskId::PartialUuid("abcd1234-1234-2345-3456".to_owned()), TaskId::PartialUuid(s!("abcd1234-1234-2345-3456")),
TaskId::Uuid(Uuid::parse_str("abcd1234-1234-2345-3456-0123456789ab").unwrap()), TaskId::Uuid(Uuid::parse_str("abcd1234-1234-2345-3456-0123456789ab").unwrap()),
]); ]);
} }

View file

@ -55,7 +55,7 @@ mod test {
Command::from_argv(argv!["task", "version"]).unwrap(), Command::from_argv(argv!["task", "version"]).unwrap(),
Command { Command {
subcommand: Subcommand::Version, subcommand: Subcommand::Version,
command_name: "task".to_owned(), command_name: s!("task"),
} }
); );
} }

View file

@ -210,7 +210,7 @@ mod test {
Filter { Filter {
universe: Universe::IdList(vec![ universe: Universe::IdList(vec![
TaskId::WorkingSetId(1), TaskId::WorkingSetId(1),
TaskId::PartialUuid("abcd1234".to_owned()), TaskId::PartialUuid(s!("abcd1234")),
]), ]),
..Default::default() ..Default::default()
} }

View file

@ -155,7 +155,7 @@ mod test {
assert_eq!( assert_eq!(
modification, modification,
Modification { Modification {
description: DescriptionMod::Set("newdesc".to_owned()), description: DescriptionMod::Set(s!("newdesc")),
..Default::default() ..Default::default()
} }
); );
@ -168,7 +168,7 @@ mod test {
assert_eq!( assert_eq!(
modification, modification,
Modification { Modification {
add_tags: set!["abc".to_owned(), "def".to_owned()], add_tags: set![s!("abc"), s!("def")],
..Default::default() ..Default::default()
} }
); );
@ -181,7 +181,7 @@ mod test {
assert_eq!( assert_eq!(
modification, modification,
Modification { Modification {
description: DescriptionMod::Set("new desc fun".to_owned()), description: DescriptionMod::Set(s!("new desc fun")),
..Default::default() ..Default::default()
} }
); );
@ -195,9 +195,9 @@ mod test {
assert_eq!( assert_eq!(
modification, modification,
Modification { Modification {
description: DescriptionMod::Set("new desc fun".to_owned()), description: DescriptionMod::Set(s!("new desc fun")),
add_tags: set!["next".to_owned()], add_tags: set![s!("next")],
remove_tags: set!["daytime".to_owned()], remove_tags: set![s!("daytime")],
..Default::default() ..Default::default()
} }
); );

View file

@ -409,7 +409,7 @@ mod test {
fn test_add_description() { fn test_add_description() {
let subcommand = Subcommand::Add { let subcommand = Subcommand::Add {
modification: Modification { modification: Modification {
description: DescriptionMod::Set("foo".to_owned()), description: DescriptionMod::Set(s!("foo")),
..Default::default() ..Default::default()
}, },
}; };
@ -423,7 +423,7 @@ mod test {
fn test_add_description_multi() { fn test_add_description_multi() {
let subcommand = Subcommand::Add { let subcommand = Subcommand::Add {
modification: Modification { modification: Modification {
description: DescriptionMod::Set("foo bar".to_owned()), description: DescriptionMod::Set(s!("foo bar")),
..Default::default() ..Default::default()
}, },
}; };
@ -441,7 +441,7 @@ mod test {
..Default::default() ..Default::default()
}, },
modification: Modification { modification: Modification {
description: DescriptionMod::Set("foo bar".to_owned()), description: DescriptionMod::Set(s!("foo bar")),
..Default::default() ..Default::default()
}, },
}; };
@ -459,7 +459,7 @@ mod test {
..Default::default() ..Default::default()
}, },
modification: Modification { modification: Modification {
description: DescriptionMod::Append("foo bar".to_owned()), description: DescriptionMod::Append(s!("foo bar")),
..Default::default() ..Default::default()
}, },
}; };
@ -477,7 +477,7 @@ mod test {
..Default::default() ..Default::default()
}, },
modification: Modification { modification: Modification {
description: DescriptionMod::Prepend("foo bar".to_owned()), description: DescriptionMod::Prepend(s!("foo bar")),
..Default::default() ..Default::default()
}, },
}; };
@ -513,7 +513,7 @@ mod test {
..Default::default() ..Default::default()
}, },
modification: Modification { modification: Modification {
description: DescriptionMod::Set("now-finished".to_owned()), description: DescriptionMod::Set(s!("now-finished")),
status: Some(Status::Completed), status: Some(Status::Completed),
..Default::default() ..Default::default()
}, },
@ -551,7 +551,7 @@ mod test {
}, },
modification: Modification { modification: Modification {
active: Some(true), active: Some(true),
description: DescriptionMod::Set("mod".to_owned()), description: DescriptionMod::Set(s!("mod")),
..Default::default() ..Default::default()
}, },
}; };
@ -587,7 +587,7 @@ mod test {
..Default::default() ..Default::default()
}, },
modification: Modification { modification: Modification {
description: DescriptionMod::Set("mod".to_owned()), description: DescriptionMod::Set(s!("mod")),
active: Some(false), active: Some(false),
..Default::default() ..Default::default()
}, },

View file

@ -27,7 +27,7 @@ mod test {
let mut w = test_writer(); let mut w = test_writer();
let mut replica = test_replica(); let mut replica = test_replica();
let modification = Modification { let modification = Modification {
description: DescriptionMod::Set("my description".to_owned()), description: DescriptionMod::Set(s!("my description")),
..Default::default() ..Default::default()
}; };
execute(&mut w, &mut replica, modification).unwrap(); execute(&mut w, &mut replica, modification).unwrap();

View file

@ -20,12 +20,12 @@ mod test {
#[test] #[test]
fn test_summary() { fn test_summary() {
let mut w = test_writer(); let mut w = test_writer();
execute(&mut w, "task".to_owned(), true).unwrap(); execute(&mut w, s!("task"), true).unwrap();
} }
#[test] #[test]
fn test_long() { fn test_long() {
let mut w = test_writer(); let mut w = test_writer();
execute(&mut w, "task".to_owned(), false).unwrap(); execute(&mut w, s!("task"), false).unwrap();
} }
} }

View file

@ -52,9 +52,7 @@ mod test {
fn test_info() { fn test_info() {
let mut w = test_writer(); let mut w = test_writer();
let mut replica = test_replica(); let mut replica = test_replica();
replica replica.new_task(Status::Pending, s!("my task")).unwrap();
.new_task(Status::Pending, "my task".to_owned())
.unwrap();
let filter = Filter { let filter = Filter {
..Default::default() ..Default::default()

View file

@ -41,9 +41,7 @@ mod test {
fn test_list() { fn test_list() {
let mut w = test_writer(); let mut w = test_writer();
let mut replica = test_replica(); let mut replica = test_replica();
replica replica.new_task(Status::Pending, s!("my task")).unwrap();
.new_task(Status::Pending, "my task".to_owned())
.unwrap();
let report = Report { let report = Report {
filter: Filter { filter: Filter {

View file

@ -33,14 +33,14 @@ mod test {
let mut replica = test_replica(); let mut replica = test_replica();
let task = replica let task = replica
.new_task(Status::Pending, "old description".to_owned()) .new_task(Status::Pending, s!("old description"))
.unwrap(); .unwrap();
let filter = Filter { let filter = Filter {
..Default::default() ..Default::default()
}; };
let modification = Modification { let modification = Modification {
description: DescriptionMod::Set("new description".to_owned()), description: DescriptionMod::Set(s!("new description")),
..Default::default() ..Default::default()
}; };
execute(&mut w, &mut replica, filter, modification).unwrap(); execute(&mut w, &mut replica, filter, modification).unwrap();

View file

@ -124,9 +124,9 @@ mod test {
fn exact_ids() { fn exact_ids() {
let mut replica = test_replica(); let mut replica = test_replica();
let t1 = replica.new_task(Status::Pending, "A".to_owned()).unwrap(); let t1 = replica.new_task(Status::Pending, s!("A")).unwrap();
let t2 = replica.new_task(Status::Completed, "B".to_owned()).unwrap(); let t2 = replica.new_task(Status::Completed, s!("B")).unwrap();
let _t = replica.new_task(Status::Pending, "C".to_owned()).unwrap(); let _t = replica.new_task(Status::Pending, s!("C")).unwrap();
replica.gc().unwrap(); replica.gc().unwrap();
let t1uuid = *t1.get_uuid(); let t1uuid = *t1.get_uuid();
@ -144,16 +144,16 @@ mod test {
.map(|t| t.get_description().to_owned()) .map(|t| t.get_description().to_owned())
.collect(); .collect();
filtered.sort(); filtered.sort();
assert_eq!(vec!["A".to_owned(), "B".to_owned()], filtered); assert_eq!(vec![s!("A"), s!("B")], filtered);
} }
#[test] #[test]
fn partial_ids() { fn partial_ids() {
let mut replica = test_replica(); let mut replica = test_replica();
let t1 = replica.new_task(Status::Pending, "A".to_owned()).unwrap(); let t1 = replica.new_task(Status::Pending, s!("A")).unwrap();
let t2 = replica.new_task(Status::Completed, "B".to_owned()).unwrap(); let t2 = replica.new_task(Status::Completed, s!("B")).unwrap();
let _t = replica.new_task(Status::Pending, "C".to_owned()).unwrap(); let _t = replica.new_task(Status::Pending, s!("C")).unwrap();
replica.gc().unwrap(); replica.gc().unwrap();
let t1uuid = *t1.get_uuid(); let t1uuid = *t1.get_uuid();
@ -173,16 +173,16 @@ mod test {
.map(|t| t.get_description().to_owned()) .map(|t| t.get_description().to_owned())
.collect(); .collect();
filtered.sort(); filtered.sort();
assert_eq!(vec!["A".to_owned(), "B".to_owned()], filtered); assert_eq!(vec![s!("A"), s!("B")], filtered);
} }
#[test] #[test]
fn all_tasks() { fn all_tasks() {
let mut replica = test_replica(); let mut replica = test_replica();
replica.new_task(Status::Pending, "A".to_owned()).unwrap(); replica.new_task(Status::Pending, s!("A")).unwrap();
replica.new_task(Status::Completed, "B".to_owned()).unwrap(); replica.new_task(Status::Completed, s!("B")).unwrap();
replica.new_task(Status::Deleted, "C".to_owned()).unwrap(); replica.new_task(Status::Deleted, s!("C")).unwrap();
replica.gc().unwrap(); replica.gc().unwrap();
let filter = Filter { let filter = Filter {
@ -194,10 +194,7 @@ mod test {
.map(|t| t.get_description().to_owned()) .map(|t| t.get_description().to_owned())
.collect(); .collect();
filtered.sort(); filtered.sort();
assert_eq!( assert_eq!(vec![s!("A"), s!("B"), s!("C")], filtered);
vec!["A".to_owned(), "B".to_owned(), "C".to_owned()],
filtered
);
} }
#[test] #[test]
@ -207,57 +204,54 @@ mod test {
let no: Tag = "no".try_into()?; let no: Tag = "no".try_into()?;
let mut t1 = replica let mut t1 = replica
.new_task(Status::Pending, "A".to_owned())? .new_task(Status::Pending, s!("A"))?
.into_mut(&mut replica); .into_mut(&mut replica);
t1.add_tag(&yes)?; t1.add_tag(&yes)?;
let mut t2 = replica let mut t2 = replica
.new_task(Status::Pending, "B".to_owned())? .new_task(Status::Pending, s!("B"))?
.into_mut(&mut replica); .into_mut(&mut replica);
t2.add_tag(&yes)?; t2.add_tag(&yes)?;
t2.add_tag(&no)?; t2.add_tag(&no)?;
let mut t3 = replica let mut t3 = replica
.new_task(Status::Pending, "C".to_owned())? .new_task(Status::Pending, s!("C"))?
.into_mut(&mut replica); .into_mut(&mut replica);
t3.add_tag(&no)?; 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) // look for just "yes" (A and B)
let filter = Filter { let filter = Filter {
universe: Universe::AllTasks, universe: Universe::AllTasks,
conditions: vec![Condition::HasTag("yes".to_owned())], conditions: vec![Condition::HasTag(s!("yes"))],
..Default::default() ..Default::default()
}; };
let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter)? let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter)?
.map(|t| t.get_description().to_owned()) .map(|t| t.get_description().to_owned())
.collect(); .collect();
filtered.sort(); 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) // look for tags without "no" (A, D)
let filter = Filter { let filter = Filter {
universe: Universe::AllTasks, universe: Universe::AllTasks,
conditions: vec![Condition::NoTag("no".to_owned())], conditions: vec![Condition::NoTag(s!("no"))],
..Default::default() ..Default::default()
}; };
let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter)? let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter)?
.map(|t| t.get_description().to_owned()) .map(|t| t.get_description().to_owned())
.collect(); .collect();
filtered.sort(); 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) // look for tags with "yes" and "no" (B)
let filter = Filter { let filter = Filter {
universe: Universe::AllTasks, universe: Universe::AllTasks,
conditions: vec![ conditions: vec![Condition::HasTag(s!("yes")), Condition::HasTag(s!("no"))],
Condition::HasTag("yes".to_owned()),
Condition::HasTag("no".to_owned()),
],
..Default::default() ..Default::default()
}; };
let filtered: Vec<_> = filtered_tasks(&mut replica, &filter)? let filtered: Vec<_> = filtered_tasks(&mut replica, &filter)?
.map(|t| t.get_description().to_owned()) .map(|t| t.get_description().to_owned())
.collect(); .collect();
assert_eq!(vec!["B".to_owned()], filtered); assert_eq!(vec![s!("B")], filtered);
Ok(()) Ok(())
} }
@ -266,9 +260,9 @@ mod test {
fn pending_tasks() { fn pending_tasks() {
let mut replica = test_replica(); let mut replica = test_replica();
replica.new_task(Status::Pending, "A".to_owned()).unwrap(); replica.new_task(Status::Pending, s!("A")).unwrap();
replica.new_task(Status::Completed, "B".to_owned()).unwrap(); replica.new_task(Status::Completed, s!("B")).unwrap();
replica.new_task(Status::Deleted, "C".to_owned()).unwrap(); replica.new_task(Status::Deleted, s!("C")).unwrap();
replica.gc().unwrap(); replica.gc().unwrap();
let filter = Filter { let filter = Filter {
@ -280,6 +274,6 @@ mod test {
.map(|t| t.get_description().to_owned()) .map(|t| t.get_description().to_owned())
.collect(); .collect();
filtered.sort(); filtered.sort();
assert_eq!(vec!["A".to_owned()], filtered); assert_eq!(vec![s!("A")], filtered);
} }
} }

View file

@ -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() };
);