1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
//! # Assertables: Rust crate of assert macros for testing
//! 
//! The `assertables` Rust crate provides many assert macros to improve your
//! compile-time tests and run-time reliability.
//! 
//! * Crate: [https://crates.io/crates/assertables](https://crates.io/crates/assertables)
//! * Docs: [https://docs.rs/assertables/](https://docs.rs/assertables/)
//! * Repo: [https://github.com/sixarm/assertables-rust-crate/](https://github.com/sixarm/assertables-rust-crate/)
//! * Contact: [joel@joelparkerhenderson.com](mailto:joel@joelparkerhenderson.com)
//! 
//! 
//! ## Introduction
//! 
//! The Rust programming language provides a few built-in assert macros to test code:
//! 
//! ```ignore
//! assert!()
//! assert_eq!(a, b)
//! assert_ne!(a, b)
//! ```
//! 
//! The assertables crate provides many more, so you can write smarter tests.
//! 
//! For values:
//! 
//! ```ignore
//! assert_gt!(a, b)
//! assert_lt!(a, b)
//! ```
//! 
//! For numbers:
//! 
//! ```ignore
//! assert_in_delta!(a, b, delta)
//! assert_in_epsilon!(a, b, epsilon)
//! ```
//! 
//! For strings:
//! 
//! ```ignore
//! assert_starts_with!(a, b)
//! assert_ends_with!(a, b)
//! ```
//! 
//! For matching:
//! 
//! ```ignore
//! assert_contains!(a, b)
//! assert_is_match!(a, b)
//! ```
//! 
//! For collections such as arrays, vectors, maps, sets:
//! 
//! ```ignore
//! assert_set_subset!(a, b)
//! assert_set_disjoint!(a, b)
//! ```
//! 
//! For file system paths and input/output readers:
//! 
//! ```ignore
//! assert_fs_read_to_string_eq!(path1, path2)
//! assert_io_read_to_string_eq!(reader1, reader2)
//! ```
//! 
//! For command capture of standard output and standard error:
//! 
//! ```ignore
//! assert_command_stdout_eq!(command1 stdout = command2 stdout);
//! assert_command_stderr_eq!(command1, command2);
//! ```
//! 
//! ### Benefits
//! 
//! * Your tests are more purposeful and powerful. This helps your code be more
//! reliable.
//! 
//! * Your assert failures provide more information. This helps you
//! troubleshoot faster.
//! 
//! * You gain runtime asserts. This helps you with validations and
//! verifications.
//! 
//! 
//! ### Features
//! 
//! * Easy to use: each macro is well-documented with runnable examples and
//! tests.
//! 
//! * Zero overhead: if you don't use a macro, then it's never compiled into
//! your code.
//! 
//! * Zero dependencies: the crate has no release dependencies, and just a short list of development dependencies.
//! 
//! 
//! ### Forms
//! 
//! Assertables macros come in three forms:
//! 
//! * Panic macro: `assert_*` is for typical test uses with `cargo test`.
//! 
//! * Debug macro: `debug_assert_*` is for runtime diagnostic configuration.
//! 
//! * Result macro:  `assert_*_as_result` is for runtime production configuration, such as for site reliability engineering, chaos engineering, validations, verifications, sanitizations, and more.
//! 
//! 
//! ### Naming conventions
//! 
//! Abbreviations:
//! 
//! * `eq` ≈ equal
//! 
//! * `ne` ≈ not equal.
//! 
//! * `lt` ≈ less than
//! 
//! * `le` ≈ less than or equal.
//! 
//! * `gt` ≈ greater than
//! 
//! * `ge` ≈ greater than or equal.
//! 
//! 
//! Shorthands:
//! 
//! * `path` ≈ implements `AsRef<Path>` such as `std::path::PathBuf`.
//! 
//! * `reader` ≈ implements method `.read_to_string()` such as `std::io::Read`.
//! 
//! * `matcher` ≈ implements `.is_match(…)` such as `regex::Regex`.
//! 
//! * `containee` ≈ usable inside `.contains(…)` such as a
//!   `std::string::String` substring.
//! 
//! * `set` ≈ a collection such as `::std::collections::BTreeSet`.
//! 
//! * `bag` ≈ a collection such as `::std::collections::BTreeMap` which has
//!   key counts.
//! 
//! 
//! ## Complete list of assert macros
//! 
//! 
//! ### assert_* for values
//! 
//! Compare values:
//! 
//! * `assert_eq!(a, b)` ≈ a = b
//! 
//! * `assert_ne!(a, b)` ≈ a ≠ b
//! 
//! * `assert_ge!(a, b)` ≈ a ≥ b
//! 
//! * `assert_gt!(a, b)` ≈ a > b
//! 
//! * `assert_le!(a, b)` ≈ a ≤ b
//! 
//! * `assert_lt!(a, b)` ≈ a < b
//! 
//! 
//! ## For infix operators
//! 
//! Compare values by using an infix value operator:
//! 
//! * `assert_infix!(a == b)` ≈ a == b
//! 
//! * `assert_infix!(a != b)` ≈ a ≠ b
//! 
//! * `assert_infix!(a < b)` ≈ a < b
//! 
//! * `assert_infix!(a <= b)` ≈ a ≤ b
//! 
//! * `assert_infix!(a > b)` ≈ a > b
//! 
//! * `assert_infix!(a >= b)` ≈ a ≥ b
//! 
//! Relate values by using an infix logical operator:
//! 
//! * `assert_infix!(a & b)` ≈ a ∧ b ≈ a AND b
//! 
//! * `assert_infix!(a | b)` ≈ a ∨ b ≈ a OR b
//! 
//! * `assert_infix!(a ^ b)` ≈ a ⊻ b ≈ a XOR b
//! 
//! * `assert_infix!(a && b)` ≈ a …∧ b ≈ a lazy AND b
//! 
//! * `assert_infix!(a || b)` ≈ a …∨ b ≈ a lazy OR b
//! 
//! 
//! ### For nearness
//! 
//! Compare values by using nearness math conventions:
//! 
//! * `assert_in_delta!(a, b, delta)` ≈ | a - b | ≤ delta
//! 
//! * `assert_in_epsilon(a, b, epsilon)` ≈ | a - b | ≤ epsilon * min(a, b)
//! 
//! 
//! ### For strings
//! 
//! These macros help with strings and also other structures that provide
//! matchers such as `starts_with`, `ends_width`, `contains`, and `is_match`.
//! Each macro also has a corresponding `not` version.
//! 
//! * `assert_starts_with(a, b)` ≈ a.starts_with(b)
//! 
//! * `assert_ends_with(a, b)` ≈ a.ends_with(b)
//! 
//! * `assert_contains(container, containee)` ≈ container.contains(containee)
//! 
//! * `assert_is_match(matcher, matchee)` ≈ matcher.is_match(matchee)
//! 
//! 
//! ### For much more
//! 
//! There are many more macros that are conveniently grouped into modules.
//! 
//! For enums:
//! 
//! * [`assert_option`] for `Option` (`Some`, `None`)
//! 
//! * [`assert_result`] for `Result` (`Ok`, `Err`)
//! 
//! For collections, such as arrays, vectors, lists, maps:
//! 
//! * [`assert_set`] for set collections
//! 
//! * [`assert_bag`] for bag collections
//! 
//! For functions:
//! 
//! * [`assert_fn`] for functions in general.
//! 
//! * [`assert_fn_ok`] for functions that return Result::Ok.
//! 
//! * [`assert_fn_err`] for functions that return Result::Err.
//! 
//! For readers:
//! 
//! * [`assert_fs_read_to_string`] for file system path contents.
//! 
//! * [`assert_io_read_to_string`] for input/output reader streams.
//! 
//! For external calls:
//! 
//! * [`assert_command`] for commands and their stdout & stderr.
//! 
//! * [`assert_program_args`] for programs with args and their stdout & stderr.
//! 
//! 
//! ## Forms
//! 
//! 
//! ### Forms for panic! versus Err()
//! 
//! The assert macros have three forms that you can use depending on your goals:
//! 
//! 
//! ```ignore
//! assert_gt!(a, b); // return () or panic!(…), for typical compile-time testing
//! 
//! debug_assert_gt!(a, b); // return () or panic!(…), for a non-optimized runtime
//! 
//! assert_gt_as_result!(a, b); // return Result Ok(()) or Err(…), for any runtime
//! ```
//! 
//! 
//! ### Forms for messages
//! 
//! The assert macros have forms for default messages versus custom messages.
//! 
//! ```ignore
//! assert_gt!(1, 2); // panic!("assertion failed: assert_gt(1, 2)…")
//! 
//! assert_gt!(1, 2, "message"); // panic!("message")
//! ```
//! 
//! 
//! ### Forms for comparing an other versus an expression
//! 
//! Some assert macros have forms for comparing an other versus an expression:
//! 
//! ```ignore
//! assert_io_read_to_string_eq!(reader1, reader2); // reader1.read_to_string() = reader2.read_to_string()
//! 
//! assert_io_read_to_string_eq_expr!(reader, expr); // reader1.read_to_string() = expr
//! ```
//! 
//! 
//! ## Change highlights
//! 
//! 
//! ### Version 8
//! 
//! 8.2:
//! 
//! * Add `assert_infix`
//! 
//! * Refactor into submodules for better discoverability and testability.
//! 
//! 8.1:
//! 
//! * Add Result macros `assert_result_ok` and `assert_result_err`
//! 
//! * Add Option macros `assert_option_some` and `assert_option_none`
//! 
//! 8.0:
//! 
//! * Add `assert_fs_read_to_string_*` macros for comparing files.
//! 
//! * Breaking change: rename `assert_read_to_string_*` macros to `assert_io_read_to_string_*`. If you use these macros, then please update your code to use the new naming convention.
//! 
//! 
//! ### Version 7
//! 
//! * Add `assert_in_delta`, `assert_in_epsilon`.
//! 
//! * Add `assert_fn_*` macros with multiple arities.
//! 
//! * Add `cargo release` for optimized tagged releases.
//! 
//! 
//! ### Version 6
//! 
//! * Add `assert_starts_with`, `assert_ends_with`, `assert_contains`, `assert_is_match`.
//! 
//! * Add `debug_assert_*` macros everywhere.
//! 
//! * Add `GPL-3.0` license.
//! 
//! 
//! ## Tracking
//! 
//! * Package: assertables-rust-crate
//! * Version: 8.2.0
//! * Created: 2021-03-30T15:47:49Z
//! * Updated: 2024-09-04T20:21:53Z
//! * License: MIT or Apache-2.0 or GPL-2.0 or GPL-3.0 or contact us for more
//! * Contact: Joel Parker Henderson (joel@sixarm.com)

// Assert truth
pub mod assert; // (in addition to what's provided by Rust `std`)

// Assert value comparison
pub mod assert_eq; // (in addition to what's provided by Rust `std`)
pub mod assert_ge;
pub mod assert_gt;
pub mod assert_le;
pub mod assert_lt;
pub mod assert_ne;

// Assert value nearness
pub mod assert_in_delta;
pub mod assert_in_epsilon;
// Assert value matching
pub mod assert_contains;
pub mod assert_ends_with;
pub mod assert_is_match;
pub mod assert_not_contains;
pub mod assert_not_ends_with;
pub mod assert_not_match;
pub mod assert_not_starts_with;
pub mod assert_starts_with;

// For maybes
pub mod assert_result;
pub mod assert_option;

// For collections
pub mod assert_set;
pub mod assert_bag;

// For functions
pub mod assert_fn;
pub mod assert_fn_ok;
pub mod assert_fn_err;

// For reading
pub mod assert_fs_read_to_string;
pub mod assert_io_read_to_string;

// For externals
pub mod assert_command;
pub mod assert_program_args;

// Experimental - work in progress - unsupported
pub mod assert_infix;