Skip to content

Commit

Permalink
Add assert_count
Browse files Browse the repository at this point in the history
  • Loading branch information
joelparkerhenderson committed Oct 9, 2024
1 parent 4ddceb5 commit 0f1a4cc
Show file tree
Hide file tree
Showing 802 changed files with 11,290 additions and 971 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Changes highlights for recent major versions.

* Add Poll macros: `assert_ready`, `assert_pending`, etc.

* Add length macros: `assert_len`, `assert_is_empty`, etc.
* Add length & count macros: `assert_len`, `assert_count`, `assert_is_empty`, etc.

* Add read macros: `assert_fs_read_to_string`, `assert_io_read_to_string`, etc.

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.17.0"
version = "8.18.0"
authors = ["Joel Parker Henderson <[email protected]>"]
edition = "2021"
description = "Assertables: assert macros for better testing, debugging, quality assurance, and runtime reliability."
Expand Down
109 changes: 55 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ compile-time tests and run-time reliability.

The Rust programming language provides assert macros such as `assert!(x)` to test code.

* `[assert!(a);](https://doc.rust-lang.org/std/macro.assert.html) // a is true`
* `[assert_eq!(a, b);](https://doc.rust-lang.org/std/macro.assert_eq.html) // a is equal to b`
* `[assert_ne!(a, b);](https://doc.rust-lang.org/std/macro.assert_ne.html) // a is not equal to b`
* [`assert!(a);`](https://doc.rust-lang.org/std/macro.assert.html) `// a is true`
* [`assert_eq!(a, b);`](https://doc.rust-lang.org/std/macro.assert_eq.html) `// a is equal to b`
* [`assert_ne!(a, b);`](https://doc.rust-lang.org/std/macro.assert_ne.html) `// a is not equal to b`

The assertables crate provides many more, to help you work with numbers,
strings, results, options, polls, iterators, files, streams, commands, and more.
Expand Down Expand Up @@ -54,117 +54,118 @@ Top features:
3. Runtime options: all the assertables macros have runtime versions.

Top comparison crates:
`[assert_matches](https://crates.io/crates/assert_matches)`,
`[assert_approx_eq](https://crates.io/crates/assert_approx_eq)`,
`[more_asserts](https://crates.io/crates/more_asserts)`,
`[cool_asserts](https://crates.io/crates/cool_asserts)`.
`[claims](https://crates.io/crates/claims)`.
[`assert_matches`](https://crates.io/crates/assert_matches),
[`assert_approx_eq`](https://crates.io/crates/assert_approx_eq),
[`more_asserts`](https://crates.io/crates/more_asserts),
[`cool_asserts`](https://crates.io/crates/cool_asserts).
[`claims`](https://crates.io/crates/claims).

## Highlights

Values:

* `[assert_eq!(a, b);](https://docs.rs/assertables/8.17.0/assertables/assert_eq) // equal to`
* `[assert_ne!(a, b);](https://docs.rs/assertables/8.17.0/assertables/assert_ne) // not equal to`
* `[assert_lt!(a, b);](https://docs.rs/assertables/8.17.0/assertables/assert_lt) // less than`
* `[assert_le!(a, b);](https://docs.rs/assertables/8.17.0/assertables/assert_le) // less than or equal to`
* `[assert_gt!(a, b);](https://docs.rs/assertables/8.17.0/assertables/assert_gt) // greater than`
* `[assert_ge!(a, b);](https://docs.rs/assertables/8.17.0/assertables/assert_ge) // greater than or equal to`
* [`assert_eq!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/assert_eq) `// equal to`
* [`assert_ne!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/assert_ne) `// not equal to`
* [`assert_lt!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/assert_lt) `// less than`
* [`assert_le!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/assert_le) `// less than or equal to`
* [`assert_gt!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/assert_gt) `// greater than`
* [`assert_ge!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/assert_ge) `// greater than or equal to`

Approximations:

* `[assert_approx_eq!(number, number);](https://docs.rs/assertables/8.17.0/assertables/assert_approx) // |a-b| ≤ 1e-6`
* `[assert_in_delta!(number, number, delta);](https://docs.rs/assertables/8.17.0/assertables/assert_in_delta) // |a-b| ≤ delta`
* `[assert_in_epsilon!(number, number, epsilon);](https://docs.rs/assertables/8.17.0/assertables/assert_in_epsilon) // |a-b| ≤ epsilon * min(a,b)`
* [`assert_approx_eq!(number, number);`](https://docs.rs/assertables/8.18.0/assertables/assert_approx) `// |a-b| ≤ 1e-6`
* [`assert_in_delta!(number, number, delta);`](https://docs.rs/assertables/8.18.0/assertables/assert_in_delta) `// |a-b| ≤ delta`
* [`assert_in_epsilon!(number, number, epsilon);`](https://docs.rs/assertables/8.18.0/assertables/assert_in_epsilon) `// |a-b| ≤ epsilon * min(a,b)`

Groups for iterators, chars, etc.:

* `[assert_all!(group, predicate);](https://docs.rs/assertables/8.17.0/assertables/assert_all) // group.all(predicate)`
* `[assert_any!(group, predicate);](https://docs.rs/assertables/8.17.0/assertables/assert_any) // group.any(predicate)`
* [`assert_all!(group, predicate);`](https://docs.rs/assertables/8.18.0/assertables/assert_all) `// group.all(predicate)`
* [`assert_any!(group, predicate);`](https://docs.rs/assertables/8.18.0/assertables/assert_any) `// group.any(predicate)`

Infix for order operators, logic operators, etc.:

* `[assert_infix!(a == b);](https://docs.rs/assertables/8.17.0/assertables/assert_infix) // order: == != < <= > >=`
* `[assert_infix!(a && b);](https://docs.rs/assertables/8.17.0/assertables/assert_infix) // logic: && || ^ & |`
* [`assert_infix!(a == b);`](https://docs.rs/assertables/8.18.0/assertables/assert_infix) `// order: == != < <= > >=`
* [`assert_infix!(a && b);`](https://docs.rs/assertables/8.18.0/assertables/assert_infix) `// logic: && || ^ & |`

Parts for strings, vectors, etc.:

* `[assert_starts_with!(whole, part);](https://docs.rs/assertables/8.17.0/assertables/assert_starts_with) // whole.starts_with(part)`
* `[assert_ends_with!(whole, part);](https://docs.rs/assertables/8.17.0/assertables/assert_ends_with) // whole.ends_with(part)`
* [`assert_starts_with!(whole, part);`](https://docs.rs/assertables/8.18.0/assertables/assert_starts_with) `// whole.starts_with(part)`
* [`assert_ends_with!(whole, part);`](https://docs.rs/assertables/8.18.0/assertables/assert_ends_with) `// whole.ends_with(part)`

Lengths for strings, vectors, etc.:
Lengths and counts for strings, vectors, iterators, etc.:

* `[assert_len!(item);](https://docs.rs/assertables/8.17.0/assertables/assert_len) // item.len()`
* `[assert_is_empty!(item);](https://docs.rs/assertables/8.17.0/assertables/assert_is_empty) // item.is_empty()`
* [`assert_len!(item);`](https://docs.rs/assertables/8.18.0/assertables/assert_len) `// item.len()`
* [`assert_count!(item);`](https://docs.rs/assertables/8.18.0/assertables/assert_count) `// item.count()`
* [`assert_is_empty!(item);`](https://docs.rs/assertables/8.18.0/assertables/assert_is_empty) `// item.is_empty()`

Matching for strings, regex, etc.:

* `[assert_matches!(expression, pattern);](module@crate::assert_matches) // matches!(expression, pattern)`
* `[assert_is_match!(matcher, matchee);](https://docs.rs/assertables/8.17.0/assertables/assert_is_match) // matcher.is_match(matchee)`
* `[assert_contains!(container, containee);](https://docs.rs/assertables/8.17.0/assertables/assert_contains) // container.contains(containee)`
* [`assert_matches!(expression, pattern);`](module@crate::assert_matches) `// matches!(expression, pattern)`
* [`assert_is_match!(matcher, matchee);`](https://docs.rs/assertables/8.18.0/assertables/assert_is_match) `// matcher.is_match(matchee)`
* [`assert_contains!(container, containee);`](https://docs.rs/assertables/8.18.0/assertables/assert_contains) `// container.contains(containee)`

Collections for arrays, vectors, iterators, sets, maps:

* `[assert_iter_eq!(arr1, arr2);](https://docs.rs/assertables/8.17.0/assertables/assert_iter) // eq ne lt le gt ge`
* `[assert_set_eq!(vec1, vec2);](https://docs.rs/assertables/8.17.0/assertables/assert_set) // eq ne lt le gt ge etc.`
* `[assert_bag_eq!(map1, map2);](https://docs.rs/assertables/8.17.0/assertables/assert_bag) // eq ne lt le gt ge etc.`
* [`assert_iter_eq!(arr1, arr2);`](https://docs.rs/assertables/8.18.0/assertables/assert_iter) `// eq ne lt le gt ge`
* [`assert_set_eq!(vec1, vec2);`](https://docs.rs/assertables/8.18.0/assertables/assert_set) `// eq ne lt le gt ge etc.`
* [`assert_bag_eq!(map1, map2);`](https://docs.rs/assertables/8.18.0/assertables/assert_bag) `// eq ne lt le gt ge etc.`

Result Ok/Err:

* `[assert_ok!(result);](https://docs.rs/assertables/8.17.0/assertables/assert_ok) // eq ne lt le gt ge`
* `[assert_err!(result);](https://docs.rs/assertables/8.17.0/assertables/assert_err) // eq ne lt le gt ge`
* [`assert_ok!(result);`](https://docs.rs/assertables/8.18.0/assertables/assert_ok) `// eq ne lt le gt ge`
* [`assert_err!(result);`](https://docs.rs/assertables/8.18.0/assertables/assert_err) `// eq ne lt le gt ge`

Option Some/None:

* `[assert_some!(option);](https://docs.rs/assertables/8.17.0/assertables/assert_some) // eq ne lt le gt ge`
* `[assert_none!(option);](https://docs.rs/assertables/8.17.0/assertables/assert_none)`
* [`assert_some!(option);`](https://docs.rs/assertables/8.18.0/assertables/assert_some) `// eq ne lt le gt ge`
* [`assert_none!(option);`](https://docs.rs/assertables/8.18.0/assertables/assert_none)

Poll Ready/Pending:

* `[assert_ready!(poll);](https://docs.rs/assertables/8.17.0/assertables/assert_ready) // eq ne lt le gt ge`
* `[assert_pending!(poll);](https://docs.rs/assertables/8.17.0/assertables/assert_pending)`
* [`assert_ready!(poll);`](https://docs.rs/assertables/8.18.0/assertables/assert_ready) `// eq ne lt le gt ge`
* [`assert_pending!(poll);`](https://docs.rs/assertables/8.18.0/assertables/assert_pending)

Read file system paths and input/output streams:

* `[assert_fs_read_to_string_eq!(path1, path2);](https://docs.rs/assertables/8.17.0/assertables/assert_fs_read_to_string) // eq ne lt le gt ge`
* `[assert_io_read_to_string_eq!(stream1, stream2);](https://docs.rs/assertables/8.17.0/assertables/assert_io_read_to_string) // eq ne lt le gt ge`
* [`assert_fs_read_to_string_eq!(path1, path2);`](https://docs.rs/assertables/8.18.0/assertables/assert_fs_read_to_string) `// eq ne lt le gt ge`
* [`assert_io_read_to_string_eq!(stream1, stream2);`](https://docs.rs/assertables/8.18.0/assertables/assert_io_read_to_string) `// eq ne lt le gt ge`

Run commands and programs then assert on stdout or stderr:

* `[assert_command_stdout_eq!(command1, command2);](https://docs.rs/assertables/8.17.0/assertables/assert_command) // eq ne lt le gt ge etc.`
* `[assert_program_args_stdout_eq!(program1, args1, program2, args2);](https://docs.rs/assertables/8.17.0/assertables/assert_program_args) // eq ne lt le gt ge etc.`
* [`assert_command_stdout_eq!(command1, command2);`](https://docs.rs/assertables/8.18.0/assertables/assert_command) `// eq ne lt le gt ge etc.`
* [`assert_program_args_stdout_eq!(program1, args1, program2, args2);`](https://docs.rs/assertables/8.18.0/assertables/assert_program_args) `// eq ne lt le gt ge etc.`

Function comparisons, which are especially good for refactoring:

* `[assert_fn_eq!(fn1, fn2);](https://docs.rs/assertables/8.17.0/assertables/assert_fn) // functions that return values`
* `[assert_fn_ok_eq!(fn1, fn2);](https://docs.rs/assertables/8.17.0/assertables/assert_fn_ok) // functions that return Ok`
* `[assert_fn_err_eq!(fn1, fn2);](https://docs.rs/assertables/8.17.0/assertables/assert_fn_err) // functions that return Err`
* [`assert_fn_eq!(fn1, fn2);`](https://docs.rs/assertables/8.18.0/assertables/assert_fn) `// functions that return values`
* [`assert_fn_ok_eq!(fn1, fn2);`](https://docs.rs/assertables/8.18.0/assertables/assert_fn_ok) `// functions that return Ok`
* [`assert_fn_err_eq!(fn1, fn2);`](https://docs.rs/assertables/8.18.0/assertables/assert_fn_err) `// functions that return Err`


## Forms

All assertables macros have forms for different outcomes:

* `[assert_gt!(a, b);](https://docs.rs/assertables/8.17.0/assertables/macro.assert_gt.html) // panic during typical test`
* `[assert_gt_as_result!(a, b);](https://docs.rs/assertables/8.17.0/assertables/macro.assert_gt_as_result.html) // return Ok or Err`
* `[debug_assert_gt!(a, b);](https://docs.rs/assertables/8.17.0/assertables/macro.debug_assert_gt.html) // panic when in debug mode`
* [`assert_gt!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/macro.assert_gt.html) `// panic during typical test`
* [`assert_gt_as_result!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/macro.assert_gt_as_result.html) `// return Ok or Err`
* [`debug_assert_gt!(a, b);`](https://docs.rs/assertables/8.18.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.17.0/assertables/macro.assert_gt.html) // automatic error message`
* `[assert_gt!(a, b, "your text");](https://docs.rs/assertables/8.17.0/assertables/macro.assert_gt.html) // custom error message`
* [`assert_gt!(a, b);`](https://docs.rs/assertables/8.18.0/assertables/macro.assert_gt.html) `// automatic error message`
* [`assert_gt!(a, b, "your text");`](https://docs.rs/assertables/8.18.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 arbitrary expression:

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


## Tracking

* Package: assertables-rust-crate
* Version: 8.17.0
* Version: 8.18.0
* Created: 2021-03-30T15:47:49Z
* Updated: 2024-10-09T18:40:20Z
* Updated: 2024-10-09T19:23:11Z
* 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_count/assert_count_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 a count is equal to another count."><title>lib::assert_count::assert_count_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_count_eq</a></h2><div class="sidebar-elems"><h2><a href="../index.html">In lib::assert_count</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_count</a>::<wbr><a class="mod" href="#">assert_count_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_count/assert_count_eq.rs.html#1-243">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 a count is equal to another count.</p>
<p>Pseudocode:<br>
a.count() = b.count()</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="string">"x"</span>.chars();
<span class="kw">let </span>b = <span class="string">"x"</span>.chars();
<span class="macro">assert_count_eq!</span>(a, b);</code></pre></div>
<h2 id="module-macros"><a class="doc-anchor" href="#module-macros">§</a>Module macros</h2>
<ul>
<li><a href="../../macro.assert_count_eq.html" title="macro lib::assert_count_eq"><code>assert_count_eq</code></a></li>
<li><a href="../../macro.assert_count_eq_as_result.html" title="macro lib::assert_count_eq_as_result"><code>assert_count_eq_as_result</code></a></li>
<li><a href="../../macro.debug_assert_count_eq.html" title="macro lib::debug_assert_count_eq"><code>debug_assert_count_eq</code></a></li>
</ul>
</div></details></section></div></main></body></html>
1 change: 1 addition & 0 deletions doc/lib/assert_count/assert_count_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 0f1a4cc

Please sign in to comment.