Skip to content

Commit fb945da

Browse files
authored
Merge pull request #1070 from nunit/updateEqualTo
Updated EqualTo constraint
2 parents d6e7616 + 4191f42 commit fb945da

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

docs/articles/nunit/writing-tests/constraints/EqualConstraint.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Is.Zero // Equivalent to Is.EqualTo(0)
2323
## Modifiers
2424

2525
```csharp
26+
...AsCollection
2627
...IgnoreCase
2728
...IgnoreWhiteSpace // From version 4.2
28-
...AsCollection
2929
...NoClip
3030
...WithSameOffset
3131
...Within(object tolerance)
@@ -37,8 +37,7 @@ Is.Zero // Equivalent to Is.EqualTo(0)
3737
.Seconds
3838
.Milliseconds
3939
.Ticks
40-
...IgnoreCase
41-
...IgnoreWhiteSpace
40+
4241
...Using(IEqualityComparer comparer)
4342
...Using(IComparer comparer)
4443
...Using<T>(IEqualityComparer<T> comparer)
@@ -118,6 +117,8 @@ to indicate the mismatched location in both _expected_ and _actual_ values:
118117

119118
The `IgnoreWhiteSpace` can also be specified when comparing collections of strings.
120119

120+
The characters ignored are the same as for the C# `Char.IsWhiteSpace`.
121+
121122
## Comparing DateTimes and TimeSpans
122123

123124
**DateTimes** and **TimeSpans** may be compared either with or without a tolerance. A tolerance is specified using
@@ -136,7 +137,7 @@ Assert.That(later, Is.EqualTo(now).Within(TimeSpan.FromHours(3.0));
136137
Assert.That(later, Is.EqualTo(now).Within(3).Hours);
137138
```
138139

139-
## Comparing Arrays, Collections and IEnumerables
140+
## Comparing Arrays, Collections and IEnumerables with AsCollection
140141

141142
Since version 2.2, NUnit has been able to compare two single-dimensioned arrays. Beginning with version 2.4,
142143
multi-dimensioned arrays, nested arrays (arrays of arrays) and collections may be compared. With version 2.5, any

docs/snippets/Snippets.NUnit/ConstraintExamples.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ public void EqualConstraint_FloatingPoint()
3838
[Test]
3939
public void EqualConstraint_Strings()
4040
{
41-
Assert.That("Hello!", Is.Not.EqualTo("HELLO!"));
42-
Assert.That("Hello!", Is.EqualTo("HELLO!").IgnoreCase);
41+
string hello = "Hello!";
42+
Assert.That(hello, Is.Not.EqualTo("HELLO!"));
43+
Assert.That(hello, Is.EqualTo("HELLO!").IgnoreCase); // Ignores case in both actual and expected before comparing
4344

4445
string[] expected = ["Hello", "World"];
4546
string[] actual = ["HELLO", "world"];
4647
Assert.That(actual, Is.EqualTo(expected).IgnoreCase);
48+
string actualiws = "Hello my world is \r\n on fire!";
49+
string expectediws = "Hellomy world \r\n is on fire!";
50+
Assert.That(actualiws, Is.EqualTo(expectediws).IgnoreWhiteSpace); // Ignores white space in both actual and expected before comparing
4751
}
4852
#endregion
4953

0 commit comments

Comments
 (0)