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:
assert_io_read_to_string_eq!(reader1, reader2)
≈ reader1.read_to_string() = reader2.read_to_string()assert_io_read_to_string_ne!(reader1, reader2)
≈ reader1.read_to_string() ≠ reader2.read_to_string()assert_io_read_to_string_lt!(reader1, reader2)
≈ reader1.read_to_string() < reader2.read_to_string()assert_io_read_to_string_le!(reader1, reader2)
≈ reader1.read_to_string() ≤ reader2.read_to_string()assert_io_read_to_string_gt!(reader1, reader2)
≈ reader1.read_to_string() > reader2.read_to_string()assert_io_read_to_string_ge!(reader1, reader2)
≈ reader1.read_to_string() ≥ reader2.read_to_string()
Compare a reader with an expression:
assert_io_read_to_string_eq_x!(reader, expr)
≈ reader.read_to_string() = exprassert_io_read_to_string_ne_x!(reader, expr)
≈ reader.read_to_string() ≠ exprassert_io_read_to_string_lt_x!(reader, expr)
≈ reader.read_to_string() < exprassert_io_read_to_string_le_x!(reader, expr)
≈ reader.read_to_string() ≤ exprassert_io_read_to_string_gt_x!(reader, expr)
≈ reader.read_to_string() > exprassert_io_read_to_string_ge_x!(reader, expr)
≈ reader.read_to_string() ≥ expr
Compare a reader with its contents:
assert_io_read_to_string_contains!(reader, &containee)
≈ reader.read_to_string().contains(containee)assert_io_read_to_string_is_match!(reader, matcher)
≈ matcher.is_match(reader.read_to_string())
§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.