Lorenz Bung 7 years ago
parent
commit
eea960d141
2 changed files with 9 additions and 6 deletions
  1. 5
    5
      hw9/task1/src/lib.rs
  2. 4
    1
      hw9/task1/tests/task1.rs

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

1
 pub fn parse(message: &str) -> Command {
1
 pub fn parse(message: &str) -> Command {
2
-    let m : String = String::from(message);
2
+    let m: String = String::from(message);
3
     let mut line = m.lines();
3
     let mut line = m.lines();
4
     match line.next() {
4
     match line.next() {
5
         Some(x) => {
5
         Some(x) => {
13
                     let cmd = m[8..].trim_left();
13
                     let cmd = m[8..].trim_left();
14
                     Command::Control(cmd.to_string())
14
                     Command::Control(cmd.to_string())
15
                 }
15
                 }
16
-                Some("RETRIEVE") => { Command::Retrieve }
17
-                Some(_) => { Command::Error(ParseError::UnknownCommand) }
18
-                None => { Command::Error(ParseError::EmptyString) }
16
+                Some("RETRIEVE") => Command::Retrieve,
17
+                Some(_) => Command::Error(ParseError::UnknownCommand),
18
+                None => Command::Error(ParseError::EmptyString),
19
             }
19
             }
20
         }
20
         }
21
-        None => { Command::Error(ParseError::EmptyString) }
21
+        None => Command::Error(ParseError::EmptyString),
22
     }
22
     }
23
 }
23
 }
24
 
24
 

+ 4
- 1
hw9/task1/tests/task1.rs View File

25
 
25
 
26
     #[test]
26
     #[test]
27
     fn control_returns_correct_command() {
27
     fn control_returns_correct_command() {
28
-        assert_eq!(parse("CONTROL Hello"), Command::Control("Hello".to_string()))
28
+        assert_eq!(
29
+            parse("CONTROL Hello"),
30
+            Command::Control("Hello".to_string())
31
+        )
29
     }
32
     }
30
 
33
 
31
     #[test]
34
     #[test]

Loading…
Cancel
Save