Skip to content

Commit

Permalink
chore: fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ev3nvy committed Aug 31, 2023
1 parent 711d420 commit 9569bb0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow-unwrap-in-tests = true
37 changes: 13 additions & 24 deletions src/parser/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl Header {

#[cfg(test)]
mod tests {
#![allow(clippy::unreadable_literal)]
use super::*;

use std::io::Cursor;
Expand All @@ -162,11 +163,11 @@ mod tests {
($buf: ident, $error: ident) => {
let mut cursor = Cursor::new($buf);
let Err(error) = crate::Header::from_reader(&mut cursor) else {
panic!("did not throw an error");
};
panic!("did not throw an error");
};
let crate::error::ManifestError::$error(..) = error else {
panic!("some other error was thrown");
};
panic!("some other error was thrown");
};
};
}

Expand All @@ -177,10 +178,7 @@ mod tests {
fn should_parse_when_valid_header() {
let mut cursor = Cursor::new(helpers::VALID_HEADER);
if let Err(error) = Header::from_reader(&mut cursor) {
panic!(
"there was an error when parsing header, header: {:?}",
error
);
panic!("there was an error when parsing header, header: {error:?}");
};
}

Expand Down Expand Up @@ -209,44 +207,39 @@ mod tests {
fn should_throw_correct_errors_when_eof() {
// EOF when reading magic bytes
let error = Header::from_reader(&mut Cursor::new(helpers::VALID_HEADER[..3].to_owned()))
.err()
.expect("did not throw an error on missing bytes");
.expect_err("did not throw an error on missing bytes");
match error {
crate::error::ManifestError::IoError(_) => (),
_ => panic!("invalid ManifestError error when eof"),
};

// EOF when reading major
let error = Header::from_reader(&mut Cursor::new(helpers::VALID_HEADER[..4].to_owned()))
.err()
.expect("did not throw an error on missing bytes");
.expect_err("did not throw an error on missing bytes");
match error {
crate::error::ManifestError::IoError(_) => (),
_ => panic!("invalid ManifestError error when eof"),
};

// EOF when reading minor
let error = Header::from_reader(&mut Cursor::new(helpers::VALID_HEADER[..5].to_owned()))
.err()
.expect("did not throw an error on missing bytes");
.expect_err("did not throw an error on missing bytes");
match error {
crate::error::ManifestError::IoError(_) => (),
_ => panic!("invalid ManifestError error when eof"),
};

// EOF when reading flags
let error = Header::from_reader(&mut Cursor::new(helpers::VALID_HEADER[..7].to_owned()))
.err()
.expect("did not throw an error on missing bytes");
.expect_err("did not throw an error on missing bytes");
match error {
crate::error::ManifestError::IoError(_) => (),
_ => panic!("invalid ManifestError error when eof"),
};

// EOF when reading offset
let error = Header::from_reader(&mut Cursor::new(helpers::VALID_HEADER[..11].to_owned()))
.err()
.expect("did not throw an error on missing bytes");
.expect_err("did not throw an error on missing bytes");
match error {
crate::error::ManifestError::IoError(_) => (),
_ => panic!("invalid ManifestError error when eof"),
Expand Down Expand Up @@ -276,9 +269,7 @@ mod tests {
#[cfg(not(feature = "version_error"))]
{
let mut cursor = Cursor::new(buf);
if let Err(_) = Header::from_reader(&mut cursor) {
panic!("error was thrown")
}
assert!(Header::from_reader(&mut cursor).is_ok(), "error was thrown");
}

#[cfg(feature = "version_error")]
Expand All @@ -297,9 +288,7 @@ mod tests {
#[cfg(not(feature = "version_error"))]
{
let mut cursor = Cursor::new(buf);
if let Err(_) = Header::from_reader(&mut cursor) {
panic!("error was thrown")
}
assert!(Header::from_reader(&mut cursor).is_ok(), "error was thrown");
}

#[cfg(feature = "version_error")]
Expand Down

0 comments on commit 9569bb0

Please sign in to comment.