Skip to content

Commit

Permalink
Add assert_iter* iterator macros
Browse files Browse the repository at this point in the history
  • Loading branch information
joelparkerhenderson committed Oct 2, 2024
1 parent 3719c04 commit e88e567
Show file tree
Hide file tree
Showing 598 changed files with 7,332 additions and 2,305 deletions.
10 changes: 6 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Changes highlights for recent major versions.

## Version 8.x

* Add Result macros: `assert_ok`, `assert_err`, et al.
* Add Iterator macros: `assert_iter_eq`, `assert_iter_ne`, etc.

* Add Option macros: `assert_some`, `assert_none`, et al.
* Add Result macros: `assert_ok`, `assert_err`, etc.

* Add Poll macros: `assert_ready`, `assert_pending`, et al.
* Add Option macros: `assert_some`, `assert_none`, etc.

* Add read macros: `assert_fs_read_to_string_*`, `assert_io_read_to_string_*`, et al.
* Add Poll macros: `assert_ready`, `assert_pending`, etc.

* Add read macros: `assert_fs_read_to_string_*`, `assert_io_read_to_string_*`, etc.

* Add approx macros: `assert_approx_eq`, `assert_approx_ne`.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "assertables"
version = "8.11.0"
version = "8.12.0"
authors = ["Joel Parker Henderson <[email protected]>"]
edition = "2021"
description = "Assertables: assert macros for better testing, debugging, quality assurance, and runtime reliability."
Expand Down
110 changes: 59 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ The assertables crate provides many more, so you can write smarter tests.

Examples:

* [`assert_lt!(1, 2)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_lt.html) `// compare less than`
* [`assert_approx_eq!(1.0000001, 1.0000002)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_approx_eq.html) `// compare floats`
* [`assert_starts_with!("hello world", "hello")`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_starts_with.html) `// compare strings`
* [`assert_fs_read_to_string_eq!("a.txt", "b.txt")`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_fs_read_to_string_eq.html) `// compare files`
* [`assert_lt!(1, 2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_lt.html) `// compare less than`
* [`assert_approx_eq!(1.0000001, 1.0000002)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_approx_eq.html) `// compare floats`
* [`assert_starts_with!("hello world", "hello")`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_starts_with.html) `// compare strings`
* [`assert_fs_read_to_string_eq!("a.txt", "b.txt")`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_fs_read_to_string_eq.html) `// compare files`

Top 3 benefits:

Expand All @@ -42,121 +42,129 @@ To use this crate, add it to your `Cargo.toml` file:

```toml
[dev-dependencies]
assertables = "8.11.0"
assertables = "8.12.0"
```

## Assert macros

For values:

* [`assert_lt!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_lt.html) `// less than`
* [`assert_le!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_le.html) `// less than or equal`
* [`assert_gt!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_gt.html) `// greater than`
* [`assert_ge!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_ge.html) `// greater than or equal`
* [`assert_lt!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_lt.html) `// less than`
* [`assert_le!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_le.html) `// less than or equal`
* [`assert_gt!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_gt.html) `// greater than`
* [`assert_ge!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_ge.html) `// greater than or equal`

For approximation:

* [`assert_approx_eq!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_approx_eq.html)
* [`assert_approx_ne!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_approx_ne.html)
* [`assert_approx_eq!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_approx_eq.html)
* [`assert_approx_ne!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_approx_ne.html)

For strings:

* [`assert_starts_with!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_starts_with.html)
* [`assert_ends_with!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_ends_with.html)
* [`assert_starts_with!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_starts_with.html)
* [`assert_ends_with!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_ends_with.html)

For matching:

* [`assert_contains!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_contains.html)
* [`assert_is_match!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_is_match.html)
* [`assert_contains!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_contains.html)
* [`assert_is_match!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_is_match.html)

For infix operators:

* [`assert_infix!(a == b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_infix.html) ([more](https://docs.rs/assertables/8.11.0/assertables/assert_infix))
* [`assert_infix!(a && b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_infix.html) ([more](https://docs.rs/assertables/8.11.0/assertables/assert_infix))
* [`assert_infix!(a == b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_infix.html) ([more](https://docs.rs/assertables/8.12.0/assertables/assert_infix))
* [`assert_infix!(a && b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_infix.html) ([more](https://docs.rs/assertables/8.12.0/assertables/assert_infix))

For nearness:

* [`assert_in_delta!(a, b, delta)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_in_delta.html)
* [`assert_in_epsilon!(a, b, epsilon)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_in_epsilon.html)
* [`assert_in_delta!(a, b, delta)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_in_delta.html)
* [`assert_in_epsilon!(a, b, epsilon)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_in_epsilon.html)

For Result Ok/Err:

* [`assert_ok!(a)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_ok.html) ([eq, ne, etc.](https://docs.rs/assertables/8.11.0/assertables/assert_ok))
* [`assert_err!(a)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_err.html ([eq, ne, etc.](https://docs.rs/assertables/8.11.0/assertables/assert_err))
* [`assert_ok!(a)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_ok.html) ([eq, ne, etc.](https://docs.rs/assertables/8.12.0/assertables/assert_ok))
* [`assert_err!(a)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_err.html ([eq, ne, etc.](https://docs.rs/assertables/8.12.0/assertables/assert_err))

For Option Some/None:

* [`assert_some!(a)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_some.html) ([eq, ne, etc.](https://docs.rs/assertables/8.11.0/assertables/assert_some))
* [`assert_none!(a)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_none.html)
* [`assert_some!(a)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_some.html) ([eq, ne, etc.](https://docs.rs/assertables/8.12.0/assertables/assert_some))
* [`assert_none!(a)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_none.html)

For Poll Ready/Pending:

* [`assert_ready!(a)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_ready.html) ([eq, ne, etc.](https://docs.rs/assertables/8.11.0/assertables/assert_ready))
* [`assert_pending!(a)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_pending.html)
* [`assert_ready!(a)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_ready.html) ([eq, ne, etc.](https://docs.rs/assertables/8.12.0/assertables/assert_ready))
* [`assert_pending!(a)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_pending.html)

For collections such as arrays, vectors, maps, sets:
For collections such as arrays, vectors, iterators, sets, bags:

* [`assert_bag_eq!(collection1, collection2)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_bag_eq.html) ([more](https://docs.rs/assertables/8.11.0/assertables/assert_bag)).
* [`assert_set_eq!(collection1, collection2)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_set_eq.html) [more](https://docs.rs/assertables/8.11.0/assertables/assert_set).
* [`assert_iter_eq!(collection1, collection2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_iter_eq.html) ([eq, ne, etc.](https://docs.rs/assertables/8.12.0/assertables/assert_iter))
* [`assert_set_eq!(collection1, collection2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_set_eq.html) [eq, ne, etc.](https://docs.rs/assertables/8.12.0/assertables/assert_set))
* [`assert_bag_eq!(collection1, collection2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_bag_eq.html) ([eq, ne, etc.](https://docs.rs/assertables/8.12.0/assertables/assert_bag))

For file system paths and input/output readers:

* [`assert_fs_read_to_string_eq!(path1, path2)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_fs_read_to_string_eq.html)
* [`assert_io_read_to_string_eq!(reader1, reader2)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_io_read_to_string_eq.html)
* [`assert_fs_read_to_string_eq!(path1, path2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_fs_read_to_string_eq.html)
* [`assert_io_read_to_string_eq!(reader1, reader2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_io_read_to_string_eq.html)

For command capture of standard output and standard error:

* [`assert_command_stdout_eq!(command1, command2)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_command_stdout_eq.html)
* [`assert_program_args_stdout_eq!(program1, args1, program2, args2)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_program_args_stdout_eq.html)
* [`assert_command_stdout_eq!(command1, command2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_command_stdout_eq.html)
* [`assert_program_args_stdout_eq!(program1, args1, program2, args2)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_program_args_stdout_eq.html)

There are many more macros that are grouped into modules.

Modules for collections, such as arrays, vectors, lists, maps:
Modules for collections such as arrays, vectors, iterators, sets, bags:

* [`assert_set`](https://docs.rs/assertables/8.11.0/assertables/assert_set) for set collections
* [`assert_bag`](https://docs.rs/assertables/8.11.0/assertables/assert_bag) for bag collections
* [`assert_iter`](https://docs.rs/assertables/8.12.0/assertables/assert_iter) for iterator collections
* [`assert_set`](https://docs.rs/assertables/8.12.0/assertables/assert_set) for set collections
* [`assert_bag`](https://docs.rs/assertables/8.12.0/assertables/assert_bag) for bag collections

Modules for variants:

* [`assert_ok`](module@crate::assert_ok)/[`assert_err`](module@crate::assert_err) for Result Ok/Err.
* [`assert_some`](module@crate::assert_some)/[`assert_none`](module@crate::assert_none) for Option Some/None.
* [`assert_ready`](module@crate::assert_ready)/[`assert_pending`](module@crate::assert_pending) for Poll Ready/Pending.

Modules for functions:

* [`assert_fn`](https://docs.rs/assertables/8.11.0/assertables/assert_fn) for functions in general.
* [`assert_fn_ok`](https://docs.rs/assertables/8.11.0/assertables/assert_fn_ok) for functions that return `Result::Ok`.
* [`assert_fn_err`](https://docs.rs/assertables/8.11.0/assertables/assert_fn_err) for functions that return `Result::Err`.
* [`assert_fn`](https://docs.rs/assertables/8.12.0/assertables/assert_fn) for functions in general.
* [`assert_fn_ok`](https://docs.rs/assertables/8.12.0/assertables/assert_fn_ok) for functions that return `Result::Ok`.
* [`assert_fn_err`](https://docs.rs/assertables/8.12.0/assertables/assert_fn_err) for functions that return `Result::Err`.

Modules for readers:

* [`assert_fs_read_to_string`](https://docs.rs/assertables/8.11.0/assertables/assert_fs_read_to_string) for file system path contents.
* [`assert_io_read_to_string`](https://docs.rs/assertables/8.11.0/assertables/assert_io_read_to_string) for input/output reader streams.
* [`assert_fs_read_to_string`](https://docs.rs/assertables/8.12.0/assertables/assert_fs_read_to_string) for file system path contents.
* [`assert_io_read_to_string`](https://docs.rs/assertables/8.12.0/assertables/assert_io_read_to_string) for input/output reader streams.

Modules for external calls:

* [`assert_command`](https://docs.rs/assertables/8.11.0/assertables/assert_command) for commands with stdout/stderr.
* [`assert_program_args`](https://docs.rs/assertables/8.11.0/assertables/assert_program_args) for programs with args with stdout/stderr.
* [`assert_command`](https://docs.rs/assertables/8.12.0/assertables/assert_command) for commands with stdout/stderr.
* [`assert_program_args`](https://docs.rs/assertables/8.12.0/assertables/assert_program_args) for programs with args with stdout/stderr.


## Forms

All assertables macros have forms for different outcomes:

* [`assert_gt!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_gt.html) // panic during typical test
* [`assert_gt_as_result!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_gt_as_result.html) // return Ok or Err
* [`debug_assert_gt!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.debug_assert_gt.html) // panic when in debug mode
* [`assert_gt!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_gt.html) // panic during typical test
* [`assert_gt_as_result!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_gt_as_result.html) // return Ok or Err
* [`debug_assert_gt!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.debug_assert_gt.html) // panic when in debug mode

All assertables macros have forms for an optional message:

* [`assert_gt!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_gt.html) // automatic error message
* [`assert_gt!(a, b, "your text")`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_gt.html) // custom error message
* [`assert_gt!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_gt.html) // automatic error message
* [`assert_gt!(a, b, "your text")`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_gt.html) // custom error message

Many assertables macros have forms for comparing left hand side (LHS) and right hand side (RHS) as the same type or as an expression:

* [`assert_ok_eq!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_ok_eq.html) // Ok(…) = Ok(…)
* [`assert_ok_eq_expr!(a, b)`](https://docs.rs/assertables/8.11.0/assertables/macro.assert_ok_eq_expr.html) // Ok(…) = expression
* [`assert_ok_eq!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_ok_eq.html) // Ok(…) = Ok(…)
* [`assert_ok_eq_expr!(a, b)`](https://docs.rs/assertables/8.12.0/assertables/macro.assert_ok_eq_expr.html) // Ok(…) = expression


## Tracking

* Package: assertables-rust-crate
* Version: 8.11.0
* Version: 8.12.0
* Created: 2021-03-30T15:47:49Z
* Updated: 2024-10-01T13:11:35Z
* Updated: 2024-10-02T16:29:24Z
* License: MIT or Apache-2.0 or GPL-2.0 or GPL-3.0 or contact us for more
* Contact: Joel Parker Henderson ([email protected])
2 changes: 1 addition & 1 deletion doc/lib/all.html

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions doc/lib/assert_iter/assert_iter_eq/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Assert an iter is equal to another."><title>lib::assert_iter::assert_iter_eq - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-c5d6553a23f1e5a6.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="lib" data-themes="" data-resource-suffix="" data-rustdoc-version="1.81.0 (eeb90cda1 2024-09-04)" data-channel="1.81.0" data-search-js="search-d234aafac6c221dd.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-d2fab2bf619172d3.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../lib/index.html">lib</a></h2></div><h2 class="location"><a href="#">Module assert_iter_eq</a></h2><div class="sidebar-elems"><h2><a href="../index.html">In lib::assert_iter</a></h2></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Module <a href="../../index.html">lib</a>::<wbr><a href="../index.html">assert_iter</a>::<wbr><a class="mod" href="#">assert_iter_eq</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../../../src/lib/assert_iter/assert_iter_eq.rs.html#1-216">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Assert an iter is equal to another.</p>
<p>Pseudocode:<br>
(collection1 into iter) = (collection2 into iter)</p>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>assertables::<span class="kw-2">*</span>;
<span class="kw">let </span>a = [<span class="number">1</span>, <span class="number">2</span>];
<span class="kw">let </span>b = [<span class="number">1</span>, <span class="number">2</span>];
<span class="macro">assert_iter_eq!</span>(<span class="kw-2">&amp;</span>a, <span class="kw-2">&amp;</span>b);</code></pre></div>
<p>This implementation uses <a href="https://doc.rust-lang.org/std/collections/trait.Iterator.html"><code>std::iter::Iterator</code></a>.</p>
<h2 id="module-macros"><a class="doc-anchor" href="#module-macros">§</a>Module macros</h2>
<ul>
<li><a href="../../macro.assert_iter_eq.html" title="macro lib::assert_iter_eq"><code>assert_iter_eq</code></a></li>
<li><a href="../../macro.assert_iter_eq_as_result.html" title="macro lib::assert_iter_eq_as_result"><code>assert_iter_eq_as_result</code></a></li>
<li><a href="../../macro.debug_assert_iter_eq.html" title="macro lib::debug_assert_iter_eq"><code>debug_assert_iter_eq</code></a></li>
</ul>
</div></details></section></div></main></body></html>
1 change: 1 addition & 0 deletions doc/lib/assert_iter/assert_iter_eq/sidebar-items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {};
Loading

0 comments on commit e88e567

Please sign in to comment.