Module assert_io_read_to_string

Source
Expand description

Assert for comparing input/output reader streams.

These macros help with input/output readers, such as file handles, byte arrays, input streams, the trait ::std::io::Read, and anything that implements a method read_to_string() -> String. See tutorial below.

§Macros

Compare a reader with another reader:

Compare a reader with an expression:

Compare a reader with its contents:

§Example

use assertables::*;
use std::io::Read;

let mut a = "alfa".as_bytes();
let mut b = "alfa".as_bytes();
assert_io_read_to_string_eq!(a, b);

§Tutorial

Rust has a concept of a “reader”, such as using ::std::io::Read to read bytes, or to use the method read_to_string to read bytes into a string buffer.

use std::io::Read;
let mut reader = "hello".as_bytes();
let mut string = String::new();
let result = reader.read_to_string(&mut string);

Rust can compare a reader’s string to another reader’s string:

use std::io::Read;
let mut reader1 = "hello".as_bytes();
let mut reader2 = "world".as_bytes();
let mut a_string = String::new();
let mut b_string = String::new();
let result1 = reader1.read_to_string(&mut a_string);
let result2 = reader2.read_to_string(&mut b_string);
assert_ne!(a_string, b_string);

The assertables crate provides macros that do the reading and string buffering for you:

let mut reader1 = "hello".as_bytes();
let mut reader2 = "world".as_bytes();
assert_io_read_to_string_ne!(reader1, reader2);

Modules§

assert_io_read_to_string_contains
Assert a ::std::io::Read read_to_string() contains a pattern.
assert_io_read_to_string_eq
Assert a ::std::io::Read read_to_string() value is equal to another.
assert_io_read_to_string_eq_x
Assert a ::std::io::Read read_to_string() value is equal to an expression.
assert_io_read_to_string_ge
Assert a ::std::io::Read read_to_string() value is greater than or equal to another.
assert_io_read_to_string_ge_x
Assert a ::std::io::Read read_to_string() value is greater than or equal to an expression.
assert_io_read_to_string_gt
Assert a ::std::io::Read read_to_string() value is greater than another.
assert_io_read_to_string_gt_x
Assert a ::std::io::Read read_to_string() value is greater than an expression.
assert_io_read_to_string_is_match
Assert a ::std::io::Read read_to_string() is a match to a regex.
assert_io_read_to_string_le
Assert a ::std::io::Read read_to_string() value is less than or equal to another.
assert_io_read_to_string_le_x
Assert a ::std::io::Read read_to_string() value is less than or equal to an expression.
assert_io_read_to_string_lt
Assert a ::std::io::Read read_to_string() value is less than another.
assert_io_read_to_string_lt_x
Assert a ::std::io::Read read_to_string() value is less than an expression.
assert_io_read_to_string_matches
Assert a ::std::io::read_to_string(path) is a match to a regex.
assert_io_read_to_string_ne
Assert a ::std::io::Read read_to_string() is not equal to another.
assert_io_read_to_string_ne_x
Assert a ::std::io::Read read_to_string() is not equal to an expression.