diff --git a/tests/integers.rs b/tests/integers.rs index 2809af5..17ab7e3 100644 --- a/tests/integers.rs +++ b/tests/integers.rs @@ -35,6 +35,15 @@ fn read_char_3() { assert!(iof::ReadInto::::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() { diff --git a/tests/string.rs b/tests/string.rs index a301bf0..1c5df07 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -45,14 +45,14 @@ 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, ""); @@ -60,7 +60,7 @@ fn read_remained_line() { let d: String = reader.read_remained_line(); assert_eq!(d, ""); - assert!(iof::ReadInto::::try_read(&mut reader).is_err()); + assert!(iof::ReadInto::::try_read_line(&mut reader).is_err()); } #[test] @@ -73,6 +73,15 @@ fn read_line_spaces() { assert!(iof::ReadInto::::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() { diff --git a/tests/tuple.rs b/tests/tuple.rs index 7d453e4..b8215d1 100644 --- a/tests/tuple.rs +++ b/tests/tuple.rs @@ -13,7 +13,7 @@ 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); @@ -21,6 +21,15 @@ fn read_tuple_3_err() { 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()); diff --git a/tests/vec.rs b/tests/vec.rs index 207af4f..7e28389 100644 --- a/tests/vec.rs +++ b/tests/vec.rs @@ -13,6 +13,15 @@ fn read_n_1() { assert!(iof::ReadInto::::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 = reader.read_n(3); +} + #[test] fn read_all() -> anyhow::Result<()> { let reader = Cursor::new("3 2 1".as_bytes());