Browse Source

Reworked error types

Lorenz Bung 7 years ago
parent
commit
656e52332f
2 changed files with 13 additions and 7 deletions
  1. 10
    5
      hw9/task1/src/lib.rs
  2. 3
    2
      hw9/task1/tests/task1.rs

+ 10
- 5
hw9/task1/src/lib.rs View File

14
                     Command::Control(cmd.to_string())
14
                     Command::Control(cmd.to_string())
15
                 }
15
                 }
16
                 Some("RETRIEVE") => { Command::Retrieve }
16
                 Some("RETRIEVE") => { Command::Retrieve }
17
-                Some(_) => { Command::NotFoundError }
18
-                None => { Command::EmptyError }
17
+                Some(_) => { Command::Error(ParseError::UnknownCommand) }
18
+                None => { Command::Error(ParseError::EmptyString) }
19
             }
19
             }
20
         }
20
         }
21
-        None => { Command::EmptyError }
21
+        None => { Command::Error(ParseError::EmptyString) }
22
     }
22
     }
23
 }
23
 }
24
 
24
 
27
     Stage(String),
27
     Stage(String),
28
     Control(String),
28
     Control(String),
29
     Retrieve,
29
     Retrieve,
30
-    NotFoundError,
31
-    EmptyError,
30
+    Error(ParseError),
31
+}
32
+
33
+#[derive(Debug, PartialEq)]
34
+pub enum ParseError {
35
+    UnknownCommand,
36
+    EmptyString,
32
 }
37
 }

+ 3
- 2
hw9/task1/tests/task1.rs View File

5
     extern crate task1;
5
     extern crate task1;
6
 
6
 
7
     use self::task1::Command;
7
     use self::task1::Command;
8
+    use self::task1::ParseError;
8
     use self::task1::parse;
9
     use self::task1::parse;
9
 
10
 
10
     #[test]
11
     #[test]
11
     fn empty_returns_correct_command() {
12
     fn empty_returns_correct_command() {
12
-        assert_eq!(parse("\n"), Command::EmptyError)
13
+        assert_eq!(parse("\n"), Command::Error(ParseError::EmptyString))
13
     }
14
     }
14
 
15
 
15
     #[test]
16
     #[test]
16
     fn not_known_command_returns_correct_command() {
17
     fn not_known_command_returns_correct_command() {
17
-        assert_eq!(parse("Hello"), Command::NotFoundError)
18
+        assert_eq!(parse("Hello"), Command::Error(ParseError::UnknownCommand))
18
     }
19
     }
19
 
20
 
20
     #[test]
21
     #[test]

Loading…
Cancel
Save