瀏覽代碼

Add test for moving input after command on success

Mark Rousskov 6 年之前
父節點
當前提交
8839363814
共有 1 個文件被更改,包括 16 次插入0 次删除
  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);
+}