Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Aug 11, 2024
1 parent b218365 commit eb7234f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
9 changes: 9 additions & 0 deletions tests/integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ fn read_char_3() {
assert!(iof::ReadInto::<u32>::try_read_char(&mut reader).is_err());
}

#[test]
#[should_panic = "failed to read a non-whitespace character before EOF"]
fn read_char_empty() {
let reader = Cursor::new("".as_bytes());
let mut reader = InputStream::new(reader);

let _: u32 = reader.read_char();
}

#[test]
#[should_panic = "invalid digit found in string"]
fn read_sign_error() {
Expand Down
15 changes: 12 additions & 3 deletions tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ fn read_line() {

#[test]
fn read_remained_line() {
let reader = Cursor::new("There are 4 strings.\n\n".as_bytes());
let reader = Cursor::new("There are 4 strings.\nThere are 3 lines.\n".as_bytes());
let mut reader = InputStream::new(reader);

let a: String = reader.read_remained_line();
assert_eq!(a, "There are 4 strings.");

let b: String = reader.read_remained_line();
assert_eq!(b, "");
assert_eq!(b, "There are 3 lines.");

let c: String = reader.read_remained_line();
assert_eq!(c, "");

let d: String = reader.read_remained_line();
assert_eq!(d, "");

assert!(iof::ReadInto::<String>::try_read(&mut reader).is_err());
assert!(iof::ReadInto::<String>::try_read_line(&mut reader).is_err());
}

#[test]
Expand All @@ -73,6 +73,15 @@ fn read_line_spaces() {
assert!(iof::ReadInto::<String>::try_read(&mut reader).is_err());
}

#[test]
#[should_panic = "number too large to fit in target type"]
fn read_remained_line_from_str_err() {
let reader = Cursor::new("123456789".as_bytes());
let mut reader = InputStream::new(reader);

let _: u16 = reader.read_remained_line();
}

#[test]
#[should_panic = "failed to read a non-whitespace character before EOF"]
fn read_line_failure() {
Expand Down
11 changes: 10 additions & 1 deletion tests/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ fn read_tuple_3() {
}

#[test]
fn read_tuple_3_err() {
fn try_read_tuple_3_from_str_err() {
let reader = Cursor::new("1 2 -3".as_bytes());
let mut reader = InputStream::new(reader);

let vec: Result<(u32, u32, u32), _> = reader.try_read_tuple();
assert!(vec.is_err());
}

#[test]
#[should_panic = "invalid digit found in string"]
fn read_tuple_3_from_str_err() {
let reader = Cursor::new("1 2 -3".as_bytes());
let mut reader = InputStream::new(reader);

let _: (u32, u32, u32) = reader.read_tuple();
}

#[test]
fn read_tuple_12() {
let reader = Cursor::new("1 2 3 4 5 6 7 8 9 10 11 12".as_bytes());
Expand Down
9 changes: 9 additions & 0 deletions tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ fn read_n_1() {
assert!(iof::ReadInto::<u32>::try_read_n(&mut reader, 1).is_err());
}

#[test]
#[should_panic = "invalid digit found in string"]
fn read_n_from_str_err() {
let reader = Cursor::new("1 -2 -3".as_bytes());
let mut reader = InputStream::new(reader);

let _: Vec<u32> = reader.read_n(3);
}

#[test]
fn read_all() -> anyhow::Result<()> {
let reader = Cursor::new("3 2 1".as_bytes());
Expand Down

0 comments on commit eb7234f

Please sign in to comment.