Skip to content

Commit 82ca1c0

Browse files
committed
port xmlunit/#235 to XMLUnit.NET
1 parent 3015627 commit 82ca1c0

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## XMLUnit.NET 2.9.1 - /not released, yet/
44

5+
* added a new `FullDescription` method to `Diff` that provides a
6+
string-representation of all differences - not just the first one
7+
like `ToString` does.
8+
Based on Java PR [xmlunit/#235](https://github.com/xmlunit/xmlunit/issues/235) by
9+
[@Boiarshinov](https://github.com/Boiarshinov)
10+
511
## XMLUnit.NET 2.9.0 - /Released 2020-10-30/
612

713
* `ISource` now extends `IDisposable` to allow releasing unmanaged

src/main/net-core/Diff/Diff.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ limitations under the License.
1414

1515
using System.Collections.Generic;
1616
using System.Linq;
17+
using System.Text;
1718

1819
namespace Org.XmlUnit.Diff {
1920

@@ -106,5 +107,35 @@ public string ToString(IComparisonFormatter formatter) {
106107
}
107108
return differences.First().Comparison.ToString(formatter);
108109
}
110+
111+
/// <summary>
112+
/// Returns a string representation of this diff using
113+
/// internal IComparisonFormatter or DefaultComparisonFormatter
114+
/// if formatter wasn't set.
115+
/// </summary>
116+
/// <remarks>
117+
/// Each comparison result separated by the end of the line.
118+
/// </remarks>
119+
/// <returns>a string representation of this diff</returns>
120+
public string FullDescription() {
121+
return FullDescription(formatter);
122+
}
123+
124+
/// <summary>
125+
/// Returns a string representation of this diff using the
126+
/// given IComparisonFormatter}
127+
/// </summary>
128+
/// <param name="formatter">the formatter to use</param>
129+
/// <returns>a string representation of this diff</returns>
130+
public string FullDescription(IComparisonFormatter formatter) {
131+
if (!HasDifferences()) {
132+
return "[identical]";
133+
}
134+
StringBuilder result = new StringBuilder();
135+
foreach (Difference d in Differences) {
136+
result.AppendLine(d.Comparison.ToString(formatter));
137+
}
138+
return result.ToString().TrimEnd();
139+
}
109140
}
110141
}

0 commit comments

Comments
 (0)