Skip to content

Commit

Permalink
Update test case to compare byteascii::ByteAscii instead of Vec<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed Dec 25, 2024
1 parent 3de29ae commit 4810914
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub use crate::minmax::{Max, Min};
/// assert_eq!(expected, misc_utils::byteascii::byteascii(&bytes));
/// ```
pub mod byteascii {
use std::cmp::PartialEq;
use std::fmt;

// Map each byte to its escaped version
Expand Down Expand Up @@ -112,6 +113,17 @@ pub mod byteascii {
}
}

impl<B> PartialEq for ByteAscii<B>
where
B: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}

impl<B> Eq for ByteAscii<B> where B: Eq {}

#[test]
fn test_byteascii() {
let mut all_bytes: [u8; 256] = [0; 256];
Expand Down
3 changes: 2 additions & 1 deletion tests/read-write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use misc_utils::fs::{self, file_open_read, file_write};
use pretty_assertions::assert_eq;

Check warning on line 5 in tests/read-write.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rust_misc_utils/rust_misc_utils/tests/read-write.rs

Check warning on line 5 in tests/read-write.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rust_misc_utils/rust_misc_utils/tests/read-write.rs
use std::{fs::File, io::prelude::*, path::Path};
use tempfile::Builder;
use misc_utils::byteascii::ByteAscii;

const LOREM_IPSUM: &str = r#"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
Expand All @@ -23,7 +24,7 @@ fn assert_file_eq(expected_file: &Path, actual_file: &Path) -> Result<(), Error>
let mut actual_file = File::open(actual_file)?;
expected_file.read_to_end(&mut expected_content)?;
actual_file.read_to_end(&mut actual_content)?;
assert_eq!(expected_content, actual_content);
assert_eq!(ByteAscii(expected_content), ByteAscii(actual_content));
Ok(())
}

Expand Down

0 comments on commit 4810914

Please sign in to comment.