summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoronielfa <onielfadev@gmail.com>2020-07-31 00:43:57 +0200
committeronielfa <onielfadev@gmail.com>2020-07-31 00:43:57 +0200
commit4591912ad315700b198238b8a3d3ba3c68d3bccf (patch)
treeae0a4a1d5e2438567c53b7854a3013c7c3996312
parente794c6ecf133df248471b465a7553d454b527399 (diff)
Add basic tests
-rw-r--r--src/command.rs162
1 files changed, 133 insertions, 29 deletions
diff --git a/src/command.rs b/src/command.rs
index ae5be66..d474e35 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -104,7 +104,7 @@ fn call_on_app(s: &mut Cursive, input: &str) {
}
}
-#[derive(PartialEq)]
+#[derive(PartialEq, Debug)]
pub enum Command {
Add(String, Option<u32>, bool),
MonthPrev,
@@ -219,50 +219,154 @@ mod tests {
use super::*;
#[test]
- fn parse_add_command_with_goal() {
- let command: Vec<String> = "eat healthy 3"
- .trim()
- .split(' ')
- .into_iter()
- .map(|s| s.to_string())
- .collect();
+ fn parse_add_command() {
+ let result = Command::from_string("add eat 2");
- let verb = "add".to_owned();
- let auto = false;
+ assert!(result.is_ok());
+ match result.unwrap() {
+ Command::Add(name, goal, auto) => {
+ assert_eq!(name, "eat");
+ assert_eq!(goal.unwrap(), 2);
+ assert_eq!(auto, false);
+ }
+ _ => panic!(),
+ }
+ }
- let result = parse_add(verb, command, auto);
+ #[test]
+ fn parse_add_command_without_goal() {
+ let result = Command::from_string("add eat");
+ assert!(result.is_ok());
match result.unwrap() {
- Command::Add(name, goal, a) => {
- assert_eq!(name, "eat healthy".to_owned());
- assert_eq!(goal.unwrap(), 3);
- assert_eq!(a, auto);
+ Command::Add(name, goal, auto) => {
+ assert_eq!(name, "eat");
+ assert!(goal.is_none());
+ assert_eq!(auto, false);
+ }
+ _ => panic!(),
+ }
+ }
+
+ // #[test]
+ fn parse_add_command_with_long_name() {
+ let result = Command::from_string("add \"eat healthy\" 5");
+
+ assert!(result.is_ok());
+ match result.unwrap() {
+ Command::Add(name, goal, auto) => {
+ assert_eq!(name, "eat healthy");
+ assert_eq!(goal.unwrap(), 5);
+ assert_eq!(auto, false);
}
_ => panic!(),
}
}
#[test]
- fn parse_add_command_without_goal() {
- let command: Vec<String> = "eat healthy"
- .trim()
- .split(' ')
- .into_iter()
- .map(|s| s.to_string())
- .collect();
+ fn parse_add_auto_command() {
+ let result = Command::from_string("add-auto eat 2");
+
+ assert!(result.is_ok());
+ match result.unwrap() {
+ Command::Add(name, goal, auto) => {
+ assert_eq!(name, "eat");
+ assert_eq!(goal.unwrap(), 2);
+ assert_eq!(auto, true);
+ }
+ _ => panic!(),
+ }
+ }
- let verb = "add".to_owned();
- let auto = false;
+ #[test]
+ fn parse_delete_command() {
+ let result = Command::from_string("delete eat");
- let result = parse_add(verb, command, auto);
+ assert!(result.is_ok());
+ match result.unwrap() {
+ Command::Delete(name) => {
+ assert_eq!(name, "eat");
+ }
+ _ => panic!(),
+ }
+ }
+
+ #[test]
+ fn parse_track_up_command() {
+ let result = Command::from_string("track-up eat");
+ assert!(result.is_ok());
match result.unwrap() {
- Command::Add(name, goal, a) => {
- assert_eq!(name, "eat healthy".to_owned());
- assert!(goal.is_none());
- assert_eq!(a, auto);
+ Command::TrackUp(name) => {
+ assert_eq!(name, "eat");
}
_ => panic!(),
}
}
+
+ #[test]
+ fn parse_track_down_command() {
+ let result = Command::from_string("track-down eat");
+
+ assert!(result.is_ok());
+ match result.unwrap() {
+ Command::TrackDown(name) => {
+ assert_eq!(name, "eat");
+ }
+ _ => panic!(),
+ }
+ }
+
+ #[test]
+ fn parse_help_command() {
+ let result = Command::from_string("help add");
+
+ assert!(result.is_ok());
+ match result.unwrap() {
+ Command::Help(name) => {
+ assert_eq!(name.unwrap(), "add");
+ }
+ _ => panic!(),
+ }
+ }
+
+ #[test]
+ fn parse_month_prev_command() {
+ let result = Command::from_string("mprev");
+
+ assert!(result.is_ok());
+ assert_eq!(result.unwrap(), Command::MonthPrev);
+ }
+
+ #[test]
+ fn parse_month_next_command() {
+ let result = Command::from_string("mnext");
+
+ assert!(result.is_ok());
+ assert_eq!(result.unwrap(), Command::MonthNext);
+ }
+
+ #[test]
+ fn parse_quit_command() {
+ let result = Command::from_string("q");
+
+ assert!(result.is_ok());
+ assert_eq!(result.unwrap(), Command::Quit);
+ }
+
+ #[test]
+ fn parse_write_command() {
+ let result = Command::from_string("w");
+
+ assert!(result.is_ok());
+ assert_eq!(result.unwrap(), Command::Write);
+ }
+
+ #[test]
+ fn parse_no_command() {
+ let result = Command::from_string("");
+
+ assert!(result.is_ok());
+ assert_eq!(result.unwrap(), Command::Blank);
+ }
}