virtual-io 0.1.0

Mock stdin/out/err for testing
Documentation
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum VioFakeMessage {
    StdIn(String),
    StdOut(String),
}

/// Appends message to the list of messages while ensuring that consecutive
/// stdout messages are merged into one. This is the desired behavior since
/// two separate `print` calls appear identical to the user as a single `print`
/// call with the contents of both.
///
/// Returns true if a new message was added. False otherwise (i.e., the previous
/// message was updated).
pub fn append_stdout(messages: &mut Vec<VioFakeMessage>, message: String) -> bool {
    let last_message = messages.last_mut();
    if let Some(VioFakeMessage::StdOut(ref mut last_message)) = last_message {
        last_message.push_str(&message);
        false
    } else {
        messages.push(VioFakeMessage::StdOut(message));
        true
    }
}