Skip to content

Commit

Permalink
Merge pull request #37 from AngleSharp/devel
Browse files Browse the repository at this point in the history
v.0.18.1
  • Loading branch information
egil authored Mar 17, 2023
2 parents aa349ad + 38875ff commit e514267
Show file tree
Hide file tree
Showing 115 changed files with 5,233 additions and 5,777 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.18.1

- Fixed element comparer such that it can strictly check if the closing tags in the source markup is the same.

# 0.18.0

- Added a new comparer, which ensures element tags are closed the same way, e.g. `<br> and <br />` would not be considered equal, but `<br>` and `<br>` would be.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>AngleSharp.Diffing.Tests</AssemblyName>
<RootNamespace>AngleSharp.Diffing</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <!-- https://github.com/Tyrrrz/GitHubActionsTestLogger/issues/5 -->
<Nullable>annotations</Nullable>
<Nullable>annotations</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
139 changes: 66 additions & 73 deletions src/AngleSharp.Diffing.Tests/Core/AttributeComparisonSourceTest.cs
Original file line number Diff line number Diff line change
@@ -1,89 +1,82 @@
using System;
namespace AngleSharp.Diffing.Core;

using Shouldly;

using Xunit;

namespace AngleSharp.Diffing.Core
public class AttributeComparisonSourceTest : DiffingTestBase
{
public class AttributeComparisonSourceTest : DiffingTestBase
public AttributeComparisonSourceTest(DiffingTestFixture fixture) : base(fixture)
{
public AttributeComparisonSourceTest(DiffingTestFixture fixture) : base(fixture)
{
}

[Fact(DisplayName = "When a null is used for element source, an exception is thrown")]
public void Test003()
{
Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource(null!, new ComparisonSource()));
Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource("", new ComparisonSource()));
}

[Fact(DisplayName = "When a element source does not contain the specified attribute name, an exception is thrown")]
public void Test004()
{
var elementSource = ToComparisonSource(@"<br>", ComparisonSourceType.Control);
}

Should.Throw<ArgumentException>(() => new AttributeComparisonSource("notFoundAttr", elementSource));
}
[Fact(DisplayName = "When a null is used for element source, an exception is thrown")]
public void Test003()
{
Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource(null!, new ComparisonSource()));
Should.Throw<ArgumentNullException>(() => new AttributeComparisonSource("", new ComparisonSource()));
}

[Fact(DisplayName = "Two sources are equal if all their properties are equal")]
public void Test1()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("foo", elementSource);
[Fact(DisplayName = "When a element source does not contain the specified attribute name, an exception is thrown")]
public void Test004()
{
var elementSource = ToComparisonSource(@"<br>", ComparisonSourceType.Control);

source.Equals(otherSource).ShouldBeTrue();
source.Equals((object)otherSource).ShouldBeTrue();
(source == otherSource).ShouldBeTrue();
(source != otherSource).ShouldBeFalse();
}
Should.Throw<ArgumentException>(() => new AttributeComparisonSource("notFoundAttr", elementSource));
}

[Fact(DisplayName = "Two sources are not equal if their attribute is different")]
public void Test11()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("bar", elementSource);
[Fact(DisplayName = "Two sources are equal if all their properties are equal")]
public void Test1()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("foo", elementSource);

source.Equals(otherSource).ShouldBeTrue();
source.Equals((object)otherSource).ShouldBeTrue();
(source == otherSource).ShouldBeTrue();
(source != otherSource).ShouldBeFalse();
}

source.Equals(otherSource).ShouldBeFalse();
(source == otherSource).ShouldBeFalse();
(source != otherSource).ShouldBeTrue();
}
[Fact(DisplayName = "Two sources are not equal if their attribute is different")]
public void Test11()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("bar", elementSource);

[Fact(DisplayName = "Two sources are not equal if their element source is different")]
public void Test3()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("bar", otherElementSource);
source.Equals(otherSource).ShouldBeFalse();
(source == otherSource).ShouldBeFalse();
(source != otherSource).ShouldBeTrue();
}

source.Equals(otherSource).ShouldBeFalse();
(source == otherSource).ShouldBeFalse();
(source != otherSource).ShouldBeTrue();
}
[Fact(DisplayName = "Two sources are not equal if their element source is different")]
public void Test3()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("bar", otherElementSource);

source.Equals(otherSource).ShouldBeFalse();
(source == otherSource).ShouldBeFalse();
(source != otherSource).ShouldBeTrue();
}

[Fact(DisplayName = "GetHashCode correctly returns same value for two equal sources")]
public void Test001()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("foo", elementSource);
[Fact(DisplayName = "GetHashCode correctly returns same value for two equal sources")]
public void Test001()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("foo", elementSource);

source.GetHashCode().ShouldBe(otherSource.GetHashCode());
}
source.GetHashCode().ShouldBe(otherSource.GetHashCode());
}

[Fact(DisplayName = "GetHashCode correctly returns different values for two unequal sources")]
public void Test002()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("bar", otherElementSource);
[Fact(DisplayName = "GetHashCode correctly returns different values for two unequal sources")]
public void Test002()
{
var elementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var otherElementSource = ToComparisonSource(@"<br foo=""bar"" bar=""baz"">", ComparisonSourceType.Control);
var source = new AttributeComparisonSource("foo", elementSource);
var otherSource = new AttributeComparisonSource("bar", otherElementSource);

source.GetHashCode().ShouldNotBe(otherSource.GetHashCode());
}
source.GetHashCode().ShouldNotBe(otherSource.GetHashCode());
}
}
Loading

0 comments on commit e514267

Please sign in to comment.