-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Draft] Converter Inheritance Support (#385)
* Updated converter for inheritance. * Added tests. * Broke the two constructors apart. --------- Co-authored-by: Aria Bounds <[email protected]>
- Loading branch information
1 parent
87b651c
commit 2e3d52f
Showing
3 changed files
with
119 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using ReverseMarkdown.Converters; | ||
using ReverseMarkdown.Test.Children; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Xunit; | ||
|
||
namespace ReverseMarkdown.Test | ||
{ | ||
public class ChildConverterTests | ||
{ | ||
[Fact] | ||
public void WhenConverter_A_IsReplacedByConverter_IgnoreAWhenHasClass() | ||
{ | ||
var converter = new ReverseMarkdown.Converter(new Config(), typeof(IgnoreAWhenHasClass).Assembly); | ||
|
||
var type = converter.GetType(); | ||
var prop = type.GetField("_converters", BindingFlags.NonPublic | BindingFlags.Instance); | ||
|
||
Assert.NotNull(prop); | ||
|
||
var propValRaw = prop.GetValue(converter); | ||
|
||
Assert.NotNull(propValRaw); | ||
|
||
var propVal = (IDictionary<string, IConverter>)propValRaw; | ||
|
||
Assert.NotNull(propVal); | ||
|
||
var converters = propVal.Select(e => e.Value.GetType()).ToArray(); | ||
|
||
Assert.DoesNotContain(typeof(A), converters); | ||
Assert.Contains(typeof(IgnoreAWhenHasClass), converters); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using HtmlAgilityPack; | ||
|
||
using ReverseMarkdown.Converters; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ReverseMarkdown.Test.Children | ||
{ | ||
internal class IgnoreAWhenHasClass : A | ||
{ | ||
private readonly string _ignore = "ignore"; | ||
|
||
public IgnoreAWhenHasClass(Converter converter) : base(converter) | ||
{ } | ||
|
||
public override string Convert(HtmlNode node) | ||
{ | ||
if (node.HasClass(_ignore)) | ||
return ""; | ||
|
||
return base.Convert(node); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters