Skip to content

Commit

Permalink
Document Is.WhiteSpace and IgnoreWhiteSpace (#922)
Browse files Browse the repository at this point in the history
* Document `Is.WhiteSpace` and `IgnoreWhiteSpace`

Add link to WhiteSpaceConstraint in tables

* Add missing Usings

Ensure same order is used for all.

* Add Version 4.2 to IgnoreWhiteSpace modifiers 2a3f2d9
  • Loading branch information
OsirisTerje committed Mar 29, 2024
1 parent 75cd010 commit ffcb477
Show file tree
Hide file tree
Showing 20 changed files with 948 additions and 693 deletions.
3 changes: 3 additions & 0 deletions articles/nunit/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@
<li>
<a href="writing-tests/constraints/UniqueItemsConstraint.html" name="" title="UniqueItemsConstraint">UniqueItemsConstraint</a>
</li>
<li>
<a href="writing-tests/constraints/WhiteSpaceConstraint.html" name="" title="WhiteSpaceConstraint">WhiteSpaceConstraint</a>
</li>
<li>
<a href="writing-tests/constraints/XmlSerializableConstraint.html" name="" title="XmlSerializableConstraint">XmlSerializableConstraint</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion articles/nunit/toc.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions articles/nunit/writing-tests/constraints/AnyOfConstraint.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ <h2 id="syntax">Syntax</h2>
<pre><code class="lang-csharp">Is.AnyOf(object[] expected)
</code></pre>
<h2 id="modifiers">Modifiers</h2>
<pre><code class="lang-csharp">...Using(IComparer comparer)
...UsingPropertiesComparer() // From version 4.1
...Using&lt;T&gt;(IEqualityComparer comparer)
...Using&lt;T&gt;(Func&lt;T, T, bool&gt;)
<pre><code class="lang-csharp">...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...Using(IEqualityComparer comparer)
...Using(IComparer comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(IComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(Comparison&lt;T&gt; comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)

...Using&lt;T&gt;(Func&lt;T, T, bool&gt; comparer)
...UsingPropertiesComparer() // From version 4.1
</code></pre>
<h2 id="examples-of-use">Examples of Use</h2>
<pre><code class="lang-csharp">Assert.That(42, Is.AnyOf(0, -1, 42, 100));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ <h2 id="syntax">Syntax</h2>
<pre><code class="lang-csharp">Is.EquivalentTo(IEnumerable other)
</code></pre>
<h2 id="modifiers">Modifiers</h2>
<pre><code class="lang-csharp">...UsingPropertiesComparer() // From version 4.1
<pre><code class="lang-csharp">...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...Using(IEqualityComparer comparer)
...Using(IComparer comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(IComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(Comparison&lt;T&gt; comparer)
...Using&lt;T&gt;(Func&lt;T, T, bool&gt; comparer)
...UsingPropertiesComparer() // From version 4.1
</code></pre>
<h2 id="examples-of-use">Examples of Use</h2>
<pre><code class="lang-csharp">int[] iarray = new int[] { 1, 2, 3 };
Expand Down
6 changes: 6 additions & 0 deletions articles/nunit/writing-tests/constraints/Constraints.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ <h2 id="alphabetical-list-of-constraints">Alphabetical List of Constraints</h2>
<td><a href="UniqueItemsConstraint.html">UniqueItemsConstraint</a></td>
</tr>
<tr>
<td><a href="WhiteSpaceConstraint.html">WhiteSpaceConstraint</a></td>
</tr>
<tr>
<td><a href="XmlSerializableConstraint.html">XmlSerializableConstraint</a></td>
</tr>
</tbody>
Expand Down Expand Up @@ -386,6 +389,9 @@ <h3 id="condition-constraints">Condition Constraints</h3>
<tr>
<td><a href="TrueConstraint.html">TrueConstraint</a></td>
</tr>
<tr>
<td><a href="WhiteSpaceConstraint.html">WhiteSpaceConstraint</a></td>
</tr>
</tbody>
</table>
<h3 id="file-and-directory-constraints">File and Directory Constraints</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ <h2 id="syntax">Syntax</h2>
Does.Not.ContainKey(object)
</code></pre>
<h2 id="modifiers">Modifiers</h2>
<pre><code class="lang-csharp">...Using(IComparer comparer)
<pre><code class="lang-csharp">...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...Using(IEqualityComparer comparer)
...UsingPropertiesComparer() // From version 4.1
...Using(IComparer comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(IComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(Comparison&lt;T&gt; comparer)
...Using&lt;T&gt;(Func&lt;T, T, bool&gt; comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...Using&lt;TCollectionType, TMemberType&gt;(Func&lt;TCollectionType, TMemberType, bool&gt; comparison)
...UsingPropertiesComparer() // From version 4.1
...WithValue(object expectedValue)
</code></pre>
<h2 id="examples-of-use">Examples of Use</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ <h2 id="syntax">Syntax</h2>
Assert.That(dictionary, new DictionaryContainsKeyValuePairConstraint(&quot;HI&quot;, &quot;UNIVERSE&quot;).Using&lt;string&gt;((x, y) =&gt; StringUtil.Compare(x, y, true)));
</code></pre>
<h2 id="modifiers">Modifiers</h2>
<pre><code class="lang-csharp">...UsingPropertiesComparer() // From version 4.1
<pre><code class="lang-csharp">...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...Using(IComparer comparer)
...Using(IEqualityComparer comparer)
...Using&lt;T&gt;(IComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(Comparison&lt;T&gt; comparer)
...Using&lt;T&gt;(Func&lt;T, T, bool&gt; comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...UsingPropertiesComparer() // From version 4.1
</code></pre>
<h2 id="see-also">See also</h2>
<ul>
Expand Down
42 changes: 40 additions & 2 deletions articles/nunit/writing-tests/constraints/EqualConstraint.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ <h2 id="syntax">Syntax</h2>
</code></pre>
<h2 id="modifiers">Modifiers</h2>
<pre><code class="lang-csharp">...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...AsCollection
...NoClip
...WithSameOffset
Expand All @@ -109,12 +110,16 @@ <h2 id="modifiers">Modifiers</h2>
.Seconds
.Milliseconds
.Ticks
...UsingPropertiesComparer() // From version 4.1
...IgnoreCase
...IgnoreWhiteSpace
...Using(IEqualityComparer comparer)
...Using(IEqualityComparer&lt;T&gt; comparer)
...Using(IComparer comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(IComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(Comparison&lt;T&gt; comparer)
...Using&lt;T&gt;(Func&lt;T, T, bool&gt; comparer)
...Using&lt;TActual, TExpected&gt;(Func&lt;TActual, TExpected, bool&gt; comparer)
...UsingPropertiesComparer() // From version 4.1
</code></pre>
<h2 id="comparing-numerics">Comparing Numerics</h2>
<p>Numerics are compared based on their values. Different types may be compared successfully if their values are equal.</p>
Expand Down Expand Up @@ -148,6 +153,39 @@ <h2 id="comparing-strings">Comparing Strings</h2>
string[] expected = new string[] { &quot;Hello&quot;, &quot;World&quot; };
string[] actual = new string[] { &quot;HELLO&quot;, &quot;world&quot; };
</code></pre>
<p>Sometimes we need to compare strings irrespective of white space characters, e.g.: when comparing Json strings.
This can be done with the <code>IgnoreWhiteSpace</code> modifier.
It allows using pretty formatted Json in NUnit tests regardless
whether the code under test uses different formatting or no white space at all.</p>
<pre><code class="lang-csharp">const string prettyJson = &quot;&quot;&quot;
&quot;persons&quot;:[
{
&quot;name&quot;: &quot;John&quot;,
&quot;surname&quot;: &quot;Smith&quot;
},
{
&quot;name&quot;: &quot;Jane&quot;,
&quot;surname&quot;: &quot;Doe&quot;
}
]
&quot;&quot;&quot;;

const string condensedJson = &quot;&quot;&quot;
&quot;persons&quot;:[{&quot;name&quot;:&quot;John&quot;,&quot;surname&quot;:&quot;Smith&quot;,},{&quot;name&quot;: &quot;Jane&quot;,&quot;surname&quot;: &quot;Doe&quot;}]
&quot;&quot;&quot;;

Assert.That(condensedJson, Is.EqualTo(prettyJson).IgnoreWhiteSpace);
</code></pre>
<p>The above tests fails and the messages has been updated to include two carrets
to indicate the mismatched location in both <em>expected</em> and <em>actual</em> values:</p>
<pre><code class="lang-text"> Assert.That(condensedJson, Is.EqualTo(prettyJson).IgnoreWhiteSpace)
Expected string length 122 but was 79. Strings differ at index 65.
Expected: &quot;...,\r\n &quot;surname&quot;: &quot;Smith&quot;\r\n },\r\n {\r\n &quot;name&quot;: &quot;Jane&quot;,\r...&quot;, ignoring white-space
-----------------------------------------------^
But was: &quot;&quot;persons&quot;:[{&quot;name&quot;:&quot;John&quot;,&quot;surname&quot;:&quot;Smith&quot;,},{&quot;name&quot;: &quot;Jane&quot;...&quot;
------------------------------------------------------^
</code></pre>
<p>The <code>IgnoreWhiteSpace</code> can also be specified when comparing collections of strings.</p>
<h2 id="comparing-datetimes-and-timespans">Comparing DateTimes and TimeSpans</h2>
<p><strong>DateTimes</strong> and <strong>TimeSpans</strong> may be compared either with or without a tolerance. A tolerance is specified using
<strong>Within</strong> with either a <strong>TimeSpan</strong> as an argument or with a numeric value followed by a one of the time conversion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ <h2 id="syntax">Syntax</h2>
<pre><code class="lang-csharp">Has.Some...
</code></pre>
<h2 id="modifiers">Modifiers</h2>
<pre><code class="lang-csharp">...UsingPropertiesComparer() // From version 4.1
<pre><code class="lang-csharp">...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...Using(IEqualityComparer comparer)
...Using(IComparer comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(IComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(Comparison&lt;T&gt; comparer)
...Using&lt;TCollectionType, TMemberType&gt;(Func&lt;TCollectionType, TMemberType, bool&gt; comparer)
...UsingPropertiesComparer() // From version 4.1
</code></pre>
<h2 id="examples-of-use">Examples of Use</h2>
<pre><code class="lang-csharp">int[] iarray = new int[] { 1, 2, 3 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ <h2 id="syntax">Syntax</h2>
<pre><code class="lang-csharp">Is.Unique
</code></pre>
<h2 id="modifiers">Modifiers</h2>
<pre><code class="lang-csharp">...UsingPropertiesComparer() // From version 4.1
<pre><code class="lang-csharp">...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...Using(IEqualityComparer comparer)
...Using(IComparer comparer)
...Using&lt;T&gt;(IEqualityComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(IComparer&lt;T&gt; comparer)
...Using&lt;T&gt;(Comparison&lt;T&gt; comparer)
...Using&lt;T&gt;(Func&lt;T, T, bool&gt; comparer)
...UsingPropertiesComparer() // From version 4.1
</code></pre>
<h2 id="example-of-use">Example of Use</h2>
<pre><code class="lang-csharp">int[] iarray = new int[] { 1, 2, 3 };
Expand Down
144 changes: 144 additions & 0 deletions articles/nunit/writing-tests/constraints/WhiteSpaceConstraint.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html lang="en">

<head>
<meta charset="utf-8">
<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-PCB5BYBNM2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-PCB5BYBNM2');
</script>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>WhiteSpace Constraint | NUnit Docs </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="WhiteSpace Constraint | NUnit Docs ">


<link rel="shortcut icon" href="../../../../favicon.ico">
<link rel="stylesheet" href="../../../../styles/docfx.vendor.min.css">
<link rel="stylesheet" href="../../../../styles/docfx.css">
<link rel="stylesheet" href="../../../../styles/main.css">
<meta property="docfx:navrel" content="../../../../toc.html">
<meta property="docfx:tocrel" content="../../../toc.html">

<meta property="docfx:rel" content="../../../../">

</head>
<body data-spy="scroll" data-target="#affix" data-offset="120">
<div id="wrapper">
<header>

<nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<a class="navbar-brand" href="../../../../index.html">
<img id="logo" class="svg" src="../../../../logo.svg" alt="">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<form class="navbar-form navbar-right" role="search" id="search">
<div class="form-group">
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
</div>
</form>
</div>
</div>
</nav>

<div class="subnav navbar navbar-default">
<div class="container hide-when-search" id="breadcrumb">
<ul class="breadcrumb">
<li></li>
</ul>
</div>
</div>
</header>
<div class="container body-content">

<div id="search-results">
<div class="search-list">Search Results for <span></span></div>
<div class="sr-items">
<p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
</div>
<ul id="pagination" data-first="First" data-prev="Previous" data-next="Next" data-last="Last"></ul>
</div>
</div>
<div role="main" class="container body-content hide-when-search">

<div class="sidenav hide-when-search">
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
<div class="sidetoggle collapse" id="sidetoggle">
<div id="sidetoc"></div>
</div>
</div>
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="">
<h1 id="whitespace-constraint">WhiteSpace Constraint</h1>

<p>The <code>WhiteSpaceConstraint</code> tests if a string contains only white-space.</p>
<p>The constraint is the equivalent of
<a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.isnullorwhitespace?view=net-8.0">String.IsNullOrWhiteSpace</a></p>
<p>White-space characters are defined by the Unicode standard as interpreted by
<a href="https://learn.microsoft.com/en-us/dotnet/api/system.char.iswhitespace?view=net-8.0">Char.IsWhiteSpace</a> method.</p>
<h2 id="constructor">Constructor</h2>
<pre><code class="lang-csharp">WhiteSpaceConstraint()
</code></pre>
<h2 id="syntax">Syntax</h2>
<pre><code class="lang-csharp">Is.WhiteSpace // From version 4.2
</code></pre>
<h2 id="examples-of-use">Examples of Use</h2>
<pre><code class="lang-csharp">Assert.That(&quot; &quot;, Is.WhiteSpace);
Assert.That(&quot;A String&quot;, Is.Not.WhiteSpace);
</code></pre>

</article>
</div>

<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<div class="contribution">
<ul class="nav">
<li>
<a href="https://github.com/nunit/docs/blob/master/docs/articles/nunit/writing-tests/constraints/WhiteSpaceConstraint.md/#L1" class="contribution-link">Edit this page</a>
</li>
</ul>
</div>
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
<h5>In this article</h5>
<div></div>
</nav>
</div>
</div>
</div>
</div>

<footer>
<div class="grad-bottom"></div>
<div class="footer">
<div class="container">
<span class="pull-right">
<a href="#top">Back to top</a>
</span>
<span>Generated by <strong>DocFX</strong></span> | Copyright (c) 2018-<span id="currentYear"></span> The NUnit Project - Licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a>

</div>
</div>
</footer>
</div>

<script type="text/javascript" src="../../../../styles/docfx.vendor.min.js"></script>
<script type="text/javascript" src="../../../../styles/docfx.js"></script>
<script type="text/javascript" src="../../../../styles/main.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions articles/nunit/writing-tests/constraints/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@
<li>
<a href="UniqueItemsConstraint.html" name="" title="UniqueItemsConstraint">UniqueItemsConstraint</a>
</li>
<li>
<a href="WhiteSpaceConstraint.html" name="" title="WhiteSpaceConstraint">WhiteSpaceConstraint</a>
</li>
<li>
<a href="XmlSerializableConstraint.html" name="" title="XmlSerializableConstraint">XmlSerializableConstraint</a>
</li>
Expand Down
Loading

0 comments on commit ffcb477

Please sign in to comment.