#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("git status --porcelain=v2: malformed line {line:?} ({reason})")]
PorcelainParse {
line: String,
reason: &'static str,
},
}
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(
Self::PorcelainParse {
line: l_line,
reason: l_reason,
},
Self::PorcelainParse {
line: r_line,
reason: r_reason,
},
) => l_line == r_line && l_reason == r_reason,
}
}
}
#[cfg(test)]
mod tests {
use similar_asserts::assert_eq;
use super::*;
#[test]
fn porcelain_parse_eq_compares_line_and_reason() {
let a = Error::PorcelainParse {
line: "1 M.".to_string(),
reason: "truncated",
};
let b = Error::PorcelainParse {
line: "1 M.".to_string(),
reason: "truncated",
};
let c = Error::PorcelainParse {
line: "1 M.".to_string(),
reason: "missing tag",
};
let d = Error::PorcelainParse {
line: "different".to_string(),
reason: "truncated",
};
assert_eq!(a, b);
assert_ne!(a, c);
assert_ne!(a, d);
}
}