Skip to content

Commit

Permalink
Remove Display and update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Aug 30, 2024
1 parent 6379df2 commit 6e84d94
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub use {
read_into::{from_str::FromStr, ReadInto, ReadIntoError, ReadIntoSingle},
stdio::read_into::*,
stream::InputStream,
write_into::{display::Display, WriteInto},
write_into::WriteInto,
};

mod array;
Expand Down
2 changes: 0 additions & 2 deletions src/write_into.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{mat::Mat, stdio::STDOUT, SepBy};
use std::{io, io::Write, ops::DerefMut};

pub(crate) mod display;

macro_rules! unwrap {
($result:expr) => {
$result.unwrap_or_else(|err| panic!("{err}"))
Expand Down
40 changes: 0 additions & 40 deletions src/write_into/display.rs

This file was deleted.

29 changes: 29 additions & 0 deletions tests/ill_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use iof::WriteInto;
use std::io::{Result, Write};

struct IllData(&'static [u8]);

impl WriteInto for IllData {
fn try_write_into<S: Write>(&self, s: &mut S) -> Result<()> {
s.write(self.0)?;
Ok(())
}
}

#[test]
#[should_panic = "incomplete utf-8 byte sequence from index 0"]
fn try_write_ill_0xcc() {
let _ = IllData(b"\xcc").write_into_string();
}

#[test]
#[should_panic = "invalid utf-8 sequence of 1 bytes from index 0"]
fn try_write_ill_0xff() {
let _ = IllData(b"\xff").write_into_string();
}

#[test]
#[should_panic = "incomplete utf-8 byte sequence from index 0"]
fn try_write_ill_0xd0() {
let _ = IllData(b"\xd0").write_into_string();
}
22 changes: 21 additions & 1 deletion tests/mat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iof::*;
use std::{io::Cursor, vec};
use std::{io::Cursor, iter::repeat, vec};

#[test]
#[should_panic = "failed to read a non-whitespace character before EOF"]
Expand All @@ -22,6 +22,7 @@ fn read_m_n() {
assert_eq!(&mat[1], [4, 5, 6].as_slice());
assert_eq!(mat.len_rows(), 2);
assert_eq!(mat.len_columns(), 3);
assert_eq!(mat.iter().len(), 2);
assert_eq!(mat.iter().count(), 2);
assert_eq!(mat.iter().size_hint(), (2, Some(2)));
assert_eq!(mat.iter().last(), Some([4, 5, 6].as_slice()));
Expand Down Expand Up @@ -63,12 +64,30 @@ fn read_same_rows() {
assert_eq!(&mat[2], &[2, 3, 2]);
assert_eq!(mat.len_rows(), 3);
assert_eq!(mat.len_columns(), 3);
assert_eq!(mat.iter().len(), 3);
assert_eq!(mat.iter().count(), 3);
assert_eq!(mat.iter().size_hint(), (3, Some(3)));
assert_eq!(mat.iter().last(), Some([2, 3, 2].as_slice()));
assert_eq!(format!("{:?}", mat), "[[2, 3, 2], [2, 3, 2], [2, 3, 2]]");
assert_eq!(mat.iter().collect::<Mat<_>>(), mat);
assert_eq!(mat, Mat::with_repeat(3, vec![2, 3, 2]));

let mut iter = mat.iter();
let mut i = 0;
while let Some(row) = iter.next() {
assert_eq!(row, [2, 3, 2].as_slice());
assert_eq!(iter.len() + i + 1, mat.len_rows());
assert_eq!(
format!("{:?}", iter),
format!(
"[{}]",
repeat("[2, 3, 2]")
.take(mat.len_rows() - 1 - i)
.sep_by(", ")
)
);
i += 1;
}
}

#[test]
Expand All @@ -83,6 +102,7 @@ fn read_all_same() {
assert_eq!(&mat[1], [2, 2, 2].as_slice());
assert_eq!(mat.len_rows(), 2);
assert_eq!(mat.len_columns(), 3);
assert_eq!(mat.iter().len(), 2);
assert_eq!(mat.iter().count(), 2);
assert_eq!(mat.iter().size_hint(), (2, Some(2)));
assert_eq!(mat.iter().last(), Some([2, 2, 2].as_slice()));
Expand Down

0 comments on commit 6e84d94

Please sign in to comment.