mod input;
mod output;
mod pipe;
mod terminal;
pub use input::{BytesInput, EmptyInput, Input, InputError, StringInput};
pub use output::{BytesOutput, Output, OutputError, SinkOutput};
pub use pipe::Pipe;
pub use terminal::{InputMode, Key, KeyEvent, Size, Terminal};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bytes_round_trip_through_a_pipe() {
let pipe = Pipe::new();
let mut input = pipe.input();
let mut output = pipe.output();
output.write(b"hello ").unwrap();
output.write(b"world").unwrap();
drop(output);
let mut bytes = Vec::new();
input.read_to_end(&mut bytes).unwrap();
assert_eq!(bytes, b"hello world");
}
#[test]
fn empty_input_reports_eof() {
let mut input = EmptyInput::new();
let mut bytes = Vec::new();
input.read_to_end(&mut bytes).unwrap();
assert!(bytes.is_empty());
}
#[test]
fn bytes_input_replays_its_data() {
let mut input = BytesInput::new(b"line one\nline two\n");
let mut line = String::new();
input.read_line(&mut line).unwrap();
assert_eq!(line, "line one\n");
}
#[test]
fn bytes_output_accumulates() {
let mut output = BytesOutput::new();
output.write(b"a").unwrap();
output.write(b"b").unwrap();
assert_eq!(output.into_bytes(), b"ab");
}
#[test]
fn sink_output_discards() {
let mut output = SinkOutput::new();
output.write(b"anything").unwrap();
}
}