Browse Source

Derive PartialEq for Command

kellda 4 years ago
parent
commit
b9e3217f5b
2 changed files with 20 additions and 2 deletions
  1. 19 1
      parser/src/command.rs
  2. 1 1
      parser/src/command/relabel.rs

+ 19 - 1
parser/src/command.rs

@@ -14,7 +14,7 @@ pub fn find_commmand_start(input: &str, bot: &str) -> Option<usize> {
     input.find(&format!("@{}", bot))
 }
 
-#[derive(Debug)]
+#[derive(Debug, PartialEq)]
 pub enum Command<'a> {
     Relabel(Result<relabel::RelabelCommand, Error<'a>>),
     Assign(Result<assign::AssignCommand, Error<'a>>),
@@ -197,6 +197,24 @@ fn code_2() {
     assert!(input.parse_command().is_none());
 }
 
+#[test]
+fn edit_1() {
+    let input_old = "@bot modify labels: +bug.";
+    let mut input_old = Input::new(input_old, "bot");
+    let input_new = "Adding labels: @bot modify labels: +bug. some other text";
+    let mut input_new = Input::new(input_new, "bot");
+    assert_eq!(input_old.parse_command(), input_new.parse_command());
+}
+
+#[test]
+fn edit_2() {
+    let input_old = "@bot modify label: +bug.";
+    let mut input_old = Input::new(input_old, "bot");
+    let input_new = "@bot modify labels: +bug.";
+    let mut input_new = Input::new(input_new, "bot");
+    assert_ne!(input_old.parse_command(), input_new.parse_command());
+}
+
 #[test]
 fn move_input_along() {
     let input = "@bot modify labels: +bug. Afterwards, delete the world.";

+ 1 - 1
parser/src/command/relabel.rs

@@ -29,7 +29,7 @@ use crate::token::{Token, Tokenizer};
 use std::error::Error as _;
 use std::fmt;
 
-#[derive(Debug)]
+#[derive(Debug, PartialEq, Eq)]
 pub struct RelabelCommand(pub Vec<LabelDelta>);
 
 #[derive(Debug, PartialEq, Eq)]