Explorar o código

Add test for moving input after command on success

Mark Rousskov %!s(int64=6) %!d(string=hai) anos
pai
achega
8839363814
Modificáronse 1 ficheiros con 16 adicións e 0 borrados
  1. 16 0
      parser/src/command.rs

+ 16 - 0
parser/src/command.rs

@@ -52,3 +52,19 @@ pub fn parse_command<'a>(input: &mut &'a str, bot: &str) -> Result<Option<Comman
 
     Ok(success.pop())
 }
+
+#[test]
+fn move_input_along() {
+    let mut input = "@bot modify labels: +bug. Afterwards, delete the world.";
+    assert!(parse_command(&mut input, "bot").unwrap().is_some());
+    assert_eq!(input, " Afterwards, delete the world.");
+}
+
+#[test]
+fn move_input_along_1() {
+    let mut input = "@bot modify labels\": +bug. Afterwards, delete the world.";
+    let input_cp = input;
+    assert!(parse_command(&mut input, "bot").is_err());
+    // don't move input along if parsing the command fails
+    assert_eq!(input, input_cp);
+}