Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Aug 30, 2024
1 parent 2b3b722 commit e5b2d88
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/ill_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ impl WriteInto for IllData {
}
}

// Standard output won't return error.
#[test]
fn write_ill() {
let _ = IllData(b"\xab\xcd\xef").write();
}

#[test]
#[should_panic = "incomplete utf-8 byte sequence from index 0"]
fn try_write_ill_0xcc() {
fn try_write_to_string_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() {
fn try_write_to_string_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() {
fn try_write_to_string_ill_0xd0() {
let _ = IllData(b"\xd0").write_into_string();
}
17 changes: 17 additions & 0 deletions tests/integers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
use iof::*;
use std::io::Cursor;

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

let a: u32 = reader.try_read_single().unwrap();
assert_eq!(a, 1);

let b: u32 = reader.try_read_single().unwrap();
assert_eq!(b, 2);

let c: u32 = reader.try_read_single().unwrap();
assert_eq!(c, 3);

assert!(iof::ReadIntoSingle::<u32>::try_read_single(&mut reader).is_err());
}

#[test]
fn read_single_3() {
let reader = Cursor::new("1 2 3".as_bytes());
Expand Down
14 changes: 14 additions & 0 deletions tests/sep_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,24 @@ fn test_sep_by() {
let s = [1, 2, 3].sep_by(", ");
assert_eq!(s.to_string(), "1, 2, 3");
assert_eq!(s.try_write_into_string().unwrap(), "1, 2, 3");
assert_eq!(
format!("{:?}", s),
"SepBy { sep: \", \", iter: IntoIter([1, 2, 3]) }",
);

let s = ([0i32; 0]).sep_by(", ");
assert_eq!(s.to_string(), "");
assert_eq!(s.try_write_into_string().unwrap(), "");
assert_eq!(
format!("{:?}", s),
"SepBy { sep: \", \", iter: IntoIter([]) }",
);

let s = [1].sep_by(", ");
assert_eq!(s.to_string(), "1");
assert_eq!(s.try_write_into_string().unwrap(), "1");
assert_eq!(
format!("{:?}", s),
"SepBy { sep: \", \", iter: IntoIter([1]) }"
);
}

0 comments on commit e5b2d88

Please sign in to comment.