Reorganize and refactor, adding integration test for common library stuff
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
use common::io::{read_string, write_string};
|
||||
use std::io::Cursor;
|
||||
|
||||
#[test]
|
||||
fn it_reads_strings() {
|
||||
let buffer = [0x0, 0x3, b'F', b'o', b'o'];
|
||||
|
||||
assert_eq!(
|
||||
read_string(&mut buffer.as_ref()).unwrap(),
|
||||
"Foo".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_writes_strings() {
|
||||
let mut buffer = Cursor::new(Vec::new());
|
||||
|
||||
write_string(&mut buffer, "Foo").unwrap();
|
||||
|
||||
// Should have written exactly 5 bytes
|
||||
assert_eq!(buffer.get_ref().len(), 5usize);
|
||||
|
||||
assert_eq!(&buffer.get_ref()[0..5], [0x0, 0x3, b'F', b'o', b'o']);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
use common::request::Request;
|
||||
use std::io::Cursor;
|
||||
|
||||
const SAMPLE: [u8; 26] = [
|
||||
0x0, 0x3, b'F', b'o', b'o', 0x0, 0x4, b'B', b'a', b'z', b'0', 0x0, 0x5, b'x', b'x', b'x', b'y',
|
||||
b'y', 0x0, 0x6, b'1', b'7', b'0', b'1', b'-', b'a',
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn it_reads_requests() {
|
||||
let request = Request::from_stream(&mut Cursor::new(SAMPLE)).unwrap();
|
||||
|
||||
assert_eq!(request, Request::new("Foo", "Baz0", "xxxyy", "1701-a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_writes_requests() {
|
||||
let request = Request::new("Foo", "Baz0", "xxxyy", "1701-a");
|
||||
|
||||
let mut buffer = Cursor::new(Vec::new());
|
||||
|
||||
request.write_to_stream(&mut buffer).unwrap();
|
||||
|
||||
// Should have written exactly 5 bytes
|
||||
assert_eq!(buffer.get_ref().len(), 26usize);
|
||||
|
||||
assert_eq!(&buffer.get_ref()[0..26], SAMPLE);
|
||||
}
|
||||
Reference in New Issue
Block a user