Skip to content

Commit

Permalink
Add assert_poll_ready and assert_poll_pending
Browse files Browse the repository at this point in the history
  • Loading branch information
joelparkerhenderson committed Sep 7, 2024
1 parent c274732 commit f0b0585
Show file tree
Hide file tree
Showing 34 changed files with 1,884 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Modules for enums:

* [`assert_option`](https://docs.rs/assertables/latest/assertables/assert_option)for `Option` {`Some`, `None`}
* [`assert_result`](https://docs.rs/assertables/latest/assertables/assert_result) for `Result` {`Ok`, `Err`}
* [`assert_poll]`](https://docs.rs/assertables/latest/assertables/assert_poll) for `Poll` {`Ready`, `Pending`}

Modules for collections, such as arrays, vectors, lists, maps:

Expand Down
2 changes: 1 addition & 1 deletion doc/lib/all.html

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions doc/lib/assert_poll/assert_poll_pending/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!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 poll.is_pending() is true."><title>lib::assert_poll::assert_poll_pending - 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_poll_pending</a></h2><div class="sidebar-elems"><h2><a href="../index.html">In lib::assert_poll</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_poll</a>::<wbr><a class="mod" href="#">assert_poll_pending</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_poll/assert_poll_pending.rs.html#1-229">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 poll.is_pending() is true.</p>
<ul>
<li>
<p>If true, return <code>()</code>.</p>
</li>
<li>
<p>Otherwise, call <a href="https://doc.rust-lang.org/1.81.0/std/macro.panic.html" title="macro std::panic"><code>panic!</code></a> with a message and the values of the
expressions with their debug representations.</p>
</li>
</ul>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::task::Poll;
<span class="kw">let </span>a: Poll&lt;i8&gt; = Poll::Pending;
<span class="macro">assert_poll_pending!</span>(a);
<span class="comment">//-&gt; ()

// Panic with error message
</span><span class="kw">let </span>a: Poll&lt;i8&gt; = Poll::Ready(<span class="number">1</span>);
<span class="kw">let </span>result = panic::catch_unwind(|| {
<span class="macro">assert_poll_pending!</span>(a);
<span class="comment">//-&gt; panic!
</span>});
<span class="macro">assert!</span>(result.is_err());
<span class="kw">let </span>actual = result.unwrap_err().downcast::&lt;String&gt;().unwrap().to_string();
<span class="kw">let </span>expect = <span class="macro">concat!</span>(
<span class="string">"assertion failed: `assert_poll_pending!(expr)`\n"</span>,
<span class="string">" expr label: `a`,\n"</span>,
<span class="string">" expr debug: `Ready(1)`,\n"</span>,
<span class="string">" expr.is_pending(): `false`"</span>,
);
<span class="macro">assert_eq!</span>(actual, expect);

<span class="comment">// Panic with error message
</span><span class="kw">let </span>result = panic::catch_unwind(|| {
<span class="macro">assert_poll_pending!</span>(a, <span class="string">"message"</span>);
<span class="comment">//-&gt; panic!
</span>});
<span class="macro">assert!</span>(result.is_err());
<span class="kw">let </span>actual = result.unwrap_err().downcast::&lt;String&gt;().unwrap().to_string();
<span class="kw">let </span>expect = <span class="string">"message"</span>;
<span class="macro">assert_eq!</span>(actual, expect);</code></pre></div>
<h2 id="module-macros"><a class="doc-anchor" href="#module-macros">§</a>Module macros</h2>
<ul>
<li><a href="../../macro.assert_poll_pending.html" title="macro lib::assert_poll_pending"><code>assert_poll_pending</code></a></li>
<li><a href="../../macro.assert_poll_pending_as_result.html" title="macro lib::assert_poll_pending_as_result"><code>assert_poll_pending_as_result</code></a></li>
<li><a href="../../macro.debug_assert_poll_pending.html" title="macro lib::debug_assert_poll_pending"><code>debug_assert_poll_pending</code></a></li>
</ul>
</div></details></section></div></main></body></html>
1 change: 1 addition & 0 deletions doc/lib/assert_poll/assert_poll_pending/sidebar-items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {};
48 changes: 48 additions & 0 deletions doc/lib/assert_poll/assert_poll_ready/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!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 poll.is_ready() is true."><title>lib::assert_poll::assert_poll_ready - 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_poll_ready</a></h2><div class="sidebar-elems"><h2><a href="../index.html">In lib::assert_poll</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_poll</a>::<wbr><a class="mod" href="#">assert_poll_ready</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_poll/assert_poll_ready.rs.html#1-228">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 poll.is_ready() is true.</p>
<ul>
<li>
<p>If true, return <code>()</code>.</p>
</li>
<li>
<p>Otherwise, call <a href="https://doc.rust-lang.org/1.81.0/std/macro.panic.html" title="macro std::panic"><code>panic!</code></a> with a message and the values of the
expressions with their debug representations.</p>
</li>
</ul>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::task::Poll;
<span class="kw">let </span>a: Poll&lt;i8&gt; = Poll::Ready(<span class="number">1</span>);
<span class="macro">assert_poll_ready!</span>(a);
<span class="comment">//-&gt; ()

// Panic with error message
</span><span class="kw">let </span>a: Poll&lt;i8&gt; = Poll::Pending;
<span class="kw">let </span>result = panic::catch_unwind(|| {
<span class="macro">assert_poll_ready!</span>(a);
<span class="comment">//-&gt; panic!
</span>});
<span class="macro">assert!</span>(result.is_err());
<span class="kw">let </span>actual = result.unwrap_err().downcast::&lt;String&gt;().unwrap().to_string();
<span class="kw">let </span>expect = <span class="macro">concat!</span>(
<span class="string">"assertion failed: `assert_poll_ready!(expr)`\n"</span>,
<span class="string">" expr label: `a`,\n"</span>,
<span class="string">" expr debug: `Pending`,\n"</span>,
<span class="string">" expr.is_ready(): `false`"</span>,
);
<span class="macro">assert_eq!</span>(actual, expect);

<span class="comment">// Panic with error message
</span><span class="kw">let </span>result = panic::catch_unwind(|| {
<span class="macro">assert_poll_ready!</span>(a, <span class="string">"message"</span>);
<span class="comment">//-&gt; panic!
</span>});
<span class="macro">assert!</span>(result.is_err());
<span class="kw">let </span>actual = result.unwrap_err().downcast::&lt;String&gt;().unwrap().to_string();
<span class="kw">let </span>expect = <span class="string">"message"</span>;
<span class="macro">assert_eq!</span>(actual, expect);</code></pre></div>
<h2 id="module-macros"><a class="doc-anchor" href="#module-macros">§</a>Module macros</h2>
<ul>
<li><a href="../../macro.assert_poll_ready.html" title="macro lib::assert_poll_ready"><code>assert_poll_ready</code></a></li>
<li><a href="../../macro.assert_poll_ready_as_result.html" title="macro lib::assert_poll_ready_as_result"><code>assert_poll_ready_as_result</code></a></li>
<li><a href="../../macro.debug_assert_poll_ready.html" title="macro lib::debug_assert_poll_ready"><code>debug_assert_poll_ready</code></a></li>
</ul>
</div></details></section></div></main></body></html>
1 change: 1 addition & 0 deletions doc/lib/assert_poll/assert_poll_ready/sidebar-items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {};
25 changes: 25 additions & 0 deletions doc/lib/assert_poll/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!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 macros for `Poll` {`Ready`, `Pending`}"><title>lib::assert_poll - 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_poll</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#modules">Modules</a></li></ul></section><h2><a href="../index.html">In crate lib</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 class="mod" href="#">assert_poll</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_poll/mod.rs.html#1-29">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 macros for <code>Poll</code> {<code>Ready</code>, <code>Pending</code>}</p>
<p>These macros help compare a <code>Poll</code> that is either <code>Ready</code>, <code>Pending</code>.</p>
<p>The macros use these capabilities:</p>
<ul>
<li>
<p>implements <code>.is_ready() -&gt; boolean</code></p>
</li>
<li>
<p>implements <code>.is_pending() -&gt; boolean</code></p>
</li>
</ul>
<h2 id="macros"><a class="doc-anchor" href="#macros">§</a>Macros</h2>
<ul>
<li>
<p><a href="macro@crate::assert_poll_ok"><code>assert_poll_ok!(a)</code></a> ≈ a.is_ok()</p>
</li>
<li>
<p><a href="macro@crate::assert_poll_err"><code>assert_poll_err!(a)</code></a> ≈ a.is_err()</p>
</li>
</ul>
<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>std::task::Poll;
<span class="kw">let </span>a: Poll&lt;i8&gt; = Poll::Ready(<span class="number">1</span>);
<span class="macro">assert_poll_ready!</span>(a);</code></pre></div>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="assert_poll_pending/index.html" title="mod lib::assert_poll::assert_poll_pending">assert_poll_pending</a></div><div class="desc docblock-short">Assert poll.is_pending() is true.</div></li><li><div class="item-name"><a class="mod" href="assert_poll_ready/index.html" title="mod lib::assert_poll::assert_poll_ready">assert_poll_ready</a></div><div class="desc docblock-short">Assert poll.is_ready() is true.</div></li></ul></section></div></main></body></html>
1 change: 1 addition & 0 deletions doc/lib/assert_poll/sidebar-items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"mod":["assert_poll_pending","assert_poll_ready"]};
Loading

0 comments on commit f0b0585

Please sign in to comment.