Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Enable at startup:
public static void Initialize() =>
VerifyBunit.Initialize();
```
<sup><a href='/src/Tests/ModuleInitializer.cs#L5-L11' title='Snippet source file'>snippet source</a> | <a href='#snippet-BunitEnable' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/ModuleInitializer.cs#L3-L9' title='Snippet source file'>snippet source</a> | <a href='#snippet-BunitEnable' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

This test:
Expand Down Expand Up @@ -245,7 +245,7 @@ VerifierSettings.ScrubLinesWithReplace(
HtmlPrettyPrint.All();
VerifierSettings.ScrubLinesContaining("<script src=\"_framework/dotnet.");
```
<sup><a href='/src/Tests/ModuleInitializer.cs#L16-L35' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubbers' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/ModuleInitializer.cs#L14-L33' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubbers' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;BL0006;NU1608;NU1109</NoWarn>
<Version>13.0.4-beta.1</Version>
<Version>13.0.4</Version>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div style="color: red; font-size: 10pt">text</div>
13 changes: 13 additions & 0 deletions src/Tests/HtmlComparerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class HtmlComparerTests
{
// Regression for a NullReferenceException in AngleSharp.Diffing's StyleAttributeComparer. This style
// attribute differs from the verified file's only in whitespace and a trailing semicolon, so the two
// markup strings are not byte-equal and the html comparer parses and compares them. It used to throw
// because the parser had no CSS support, leaving each element's inline style null; the styles must now
// compare as semantically equal. The two spellings are deliberately different — keep them that way.
[Fact]
public Task StyledElement_SemanticallyEqual() =>
Verify(
"<div style=\"color:red;font-size:10pt;\">text</div>",
extension: "html");
}
4 changes: 1 addition & 3 deletions src/Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using VerifyTests.DiffPlex;

public static class ModuleInitializer
public static class ModuleInitializer
{
#region BunitEnable

Expand Down
9 changes: 8 additions & 1 deletion src/Verify.Bunit/BunitMarkupComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@

static class BunitMarkupComparer
{
// AngleSharp.Diffing compares style attributes semantically, which needs the parsed markup to carry
// a real CSS object model. A default HtmlParser has no CSS support, so an element's inline style
// parses to null and StyleAttributeComparer throws a NullReferenceException the moment two style
// attributes differ. Parsing through a CSS-enabled configuration gives every element a real
// ICssStyleDeclaration, so the style comparison works.
static readonly IConfiguration configuration = Configuration.Default.WithCss();

public static Task<CompareResult> Compare(string received, string verified, IReadOnlyDictionary<string, object> context)
{
var parser = new HtmlParser();
var parser = new HtmlParser(new(), BrowsingContext.New(configuration));
var receivedDoc = parser.ParseDocument(received);
var verifiedDoc = parser.ParseDocument(verified);
var diffs = receivedDoc.Body!.ChildNodes.CompareTo(verifiedDoc.Body!.ChildNodes);
Expand Down
Loading