Skip to content

Commit 23da45e

Browse files
weihanglobmwill
authored andcommitted
test(error): assert error variants instead of is_err
1 parent 4ae28ae commit 23da45e

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/patch/parse.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn strip_newline<T: Text + ?Sized>(s: &T) -> Result<&T> {
267267

268268
#[cfg(test)]
269269
mod tests {
270-
use super::{parse, parse_bytes};
270+
use super::{parse, parse_bytes, ParsePatchErrorKind};
271271

272272
#[test]
273273
fn test_escaped_filenames() {
@@ -288,7 +288,10 @@ mod tests {
288288
@@ -1,0 +1,1 @@
289289
+Oathbringer
290290
";
291-
parse(s).unwrap_err();
291+
assert_eq!(
292+
parse(s).unwrap_err(),
293+
ParsePatchErrorKind::InvalidCharInUnquotedFilename.into(),
294+
);
292295
parse_bytes(s.as_ref()).unwrap_err();
293296

294297
// quoted with invalid escaped characters
@@ -298,7 +301,10 @@ mod tests {
298301
@@ -1,0 +1,1 @@
299302
+Oathbringer
300303
";
301-
parse(s).unwrap_err();
304+
assert_eq!(
305+
parse(s).unwrap_err(),
306+
ParsePatchErrorKind::InvalidUnescapedChar.into(),
307+
);
302308
parse_bytes(s.as_ref()).unwrap_err();
303309

304310
// quoted with escaped characters
@@ -420,7 +426,10 @@ mod tests {
420426
@@ -1,0 +1,1 @@
421427
+content
422428
"#;
423-
parse(s).unwrap_err();
429+
assert_eq!(
430+
parse(s).unwrap_err(),
431+
ParsePatchErrorKind::InvalidEscapedChar.into(),
432+
);
424433

425434
// Non-octal digit in second position → error
426435
let s = r#"\
@@ -429,7 +438,10 @@ mod tests {
429438
@@ -1,0 +1,1 @@
430439
+content
431440
"#;
432-
parse(s).unwrap_err();
441+
assert_eq!(
442+
parse(s).unwrap_err(),
443+
ParsePatchErrorKind::InvalidEscapedChar.into(),
444+
);
433445

434446
// First octal digit > 3 → error (would overflow a byte)
435447
let s = r#"\
@@ -438,7 +450,10 @@ mod tests {
438450
@@ -1,0 +1,1 @@
439451
+content
440452
"#;
441-
parse(s).unwrap_err();
453+
assert_eq!(
454+
parse(s).unwrap_err(),
455+
ParsePatchErrorKind::InvalidEscapedChar.into(),
456+
);
442457

443458
// \101 = 'A' (0x41), first octal digit 1
444459
let s = r#"\
@@ -598,7 +613,10 @@ mod tests {
598613
@@ -1,0 +1,1 @@
599614
+Oathbringer
600615
";
601-
parse(s).unwrap_err();
616+
assert_eq!(
617+
parse(s).unwrap_err(),
618+
ParsePatchErrorKind::MultipleOriginalHeaders.into(),
619+
);
602620
}
603621

604622
#[test]

0 commit comments

Comments
 (0)