assertables/assert_io_read_to_string/
mod.rs

1//! Assert for comparing input/output reader streams.
2//!
3//! These macros help with input/output readers, such as file handles, byte arrays,
4//! input streams, the trait `::std::io::Read`, and anything that implements a
5//! method `read_to_string() -> String`. See tutorial below.
6//!
7//! ## Macros
8//!
9//! Compare a reader with another reader:
10//!
11//! * [`assert_io_read_to_string_eq!(reader1, reader2)`](macro@crate::assert_io_read_to_string_eq) ≈ reader1.read_to_string() = reader2.read_to_string()
12//! * [`assert_io_read_to_string_ne!(reader1, reader2)`](macro@crate::assert_io_read_to_string_ne) ≈ reader1.read_to_string() ≠ reader2.read_to_string()
13//! * [`assert_io_read_to_string_lt!(reader1, reader2)`](macro@crate::assert_io_read_to_string_lt) ≈ reader1.read_to_string() < reader2.read_to_string()
14//! * [`assert_io_read_to_string_le!(reader1, reader2)`](macro@crate::assert_io_read_to_string_le) ≈ reader1.read_to_string() ≤ reader2.read_to_string()
15//! * [`assert_io_read_to_string_gt!(reader1, reader2)`](macro@crate::assert_io_read_to_string_gt) ≈ reader1.read_to_string() > reader2.read_to_string()
16//! * [`assert_io_read_to_string_ge!(reader1, reader2)`](macro@crate::assert_io_read_to_string_ge) ≈ reader1.read_to_string() ≥ reader2.read_to_string()
17//!
18//! Compare a reader with an expression:
19//!
20//! * [`assert_io_read_to_string_eq_x!(reader, expr)`](macro@crate::assert_io_read_to_string_eq_x) ≈ reader.read_to_string() = expr
21//! * [`assert_io_read_to_string_ne_x!(reader, expr)`](macro@crate::assert_io_read_to_string_ne_x) ≈ reader.read_to_string() ≠ expr
22//! * [`assert_io_read_to_string_lt_x!(reader, expr)`](macro@crate::assert_io_read_to_string_lt_x) ≈ reader.read_to_string() < expr
23//! * [`assert_io_read_to_string_le_x!(reader, expr)`](macro@crate::assert_io_read_to_string_le_x) ≈ reader.read_to_string() ≤ expr
24//! * [`assert_io_read_to_string_gt_x!(reader, expr)`](macro@crate::assert_io_read_to_string_gt_x) ≈ reader.read_to_string() > expr
25//! * [`assert_io_read_to_string_ge_x!(reader, expr)`](macro@crate::assert_io_read_to_string_ge_x) ≈ reader.read_to_string() ≥ expr
26//!
27//! Compare a reader with its contents:
28//!
29//! * [`assert_io_read_to_string_contains!(reader, &containee)`](macro@crate::assert_io_read_to_string_contains) ≈ reader.read_to_string().contains(containee)
30//! * [`assert_io_read_to_string_is_match!(reader, &matcher)`](macro@crate::assert_io_read_to_string_is_match) ≈ matcher.is_match(reader.read_to_string())
31//!
32//!
33//! # Example
34//!
35//! ```rust
36//! use assertables::*;
37//! use std::io::Read;
38//!
39//! let mut a = "alfa".as_bytes();
40//! let mut b = "alfa".as_bytes();
41//! assert_io_read_to_string_eq!(a, b);
42//! ```
43//!
44//! ## Tutorial
45//!
46//! Rust has a concept of a "reader", such as using `::std::io::Read` to read bytes,
47//! or to use the method `read_to_string` to read bytes into a string buffer.
48//!
49//! ```rust
50//! use std::io::Read;
51//! let mut reader = "hello".as_bytes();
52//! let mut string = String::new();
53//! let result = reader.read_to_string(&mut string);
54//! ```
55//!
56//! Rust can compare a reader's string to another reader's string:
57//!
58//! ```rust
59//! use std::io::Read;
60//! let mut reader1 = "hello".as_bytes();
61//! let mut reader2 = "world".as_bytes();
62//! let mut a_string = String::new();
63//! let mut b_string = String::new();
64//! let result1 = reader1.read_to_string(&mut a_string);
65//! let result2 = reader2.read_to_string(&mut b_string);
66//! assert_ne!(a_string, b_string);
67//! ```
68//!
69//! The `assertables` crate provides macros that do the reading and string buffering for you:
70//!
71//! ```rust
72//! # use std::io::Read;
73//! # use assertables::*;
74//! let mut reader1 = "hello".as_bytes();
75//! let mut reader2 = "world".as_bytes();
76//! assert_io_read_to_string_ne!(reader1, reader2);
77//! ```
78
79// Compare another
80pub mod assert_io_read_to_string_eq;
81pub mod assert_io_read_to_string_ge;
82pub mod assert_io_read_to_string_gt;
83pub mod assert_io_read_to_string_le;
84pub mod assert_io_read_to_string_lt;
85pub mod assert_io_read_to_string_ne;
86
87// Compare expression
88pub mod assert_io_read_to_string_eq_x;
89pub mod assert_io_read_to_string_ge_x;
90pub mod assert_io_read_to_string_gt_x;
91pub mod assert_io_read_to_string_le_x;
92pub mod assert_io_read_to_string_lt_x;
93pub mod assert_io_read_to_string_ne_x;
94
95// Specializations
96pub mod assert_io_read_to_string_contains;
97pub mod assert_io_read_to_string_is_match;
98pub mod assert_io_read_to_string_matches; // Deprecated.