Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionado propriedade para ignorar delete ou não marcar o insert. #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 21 additions & 2 deletions HtmlDiff/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class HtmlDiff

private readonly StringBuilder _content;
private string _newText;
private string _oldText;

private string _oldText;

private static Dictionary<string, int> _specialCaseClosingTags = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
{
Expand Down Expand Up @@ -84,6 +83,16 @@ public class HtmlDiff
/// </summary>
public double OrphanMatchThreshold { get; set; }

/// <summary>
/// If true all deleted texts are not formatted.
/// </summary>
public bool IgnoreDelete { get; set; }

/// <summary>
/// If true all inserted texts are not formatted.
/// </summary>
public bool IgnoreInsert { get; set; }

/// <summary>
/// Initializes a new instance of the class.
/// </summary>
Expand Down Expand Up @@ -188,11 +197,21 @@ private void ProcessReplaceOperation(Operation operation)
private void ProcessInsertOperation(Operation operation, string cssClass)
{
List<string> text = _newWords.Where((s, pos) => pos >= operation.StartInNew && pos < operation.EndInNew).ToList();

if (IgnoreInsert)
{
_content.Append(string.Join("", text.ToArray()));
return;
}

InsertTag("ins", cssClass, text);
}

private void ProcessDeleteOperation(Operation operation, string cssClass)
{
if (IgnoreDelete)
return;

List<string> text = _oldWords.Where((s, pos) => pos >= operation.StartInOld && pos < operation.EndInOld).ToList();
InsertTag("del", cssClass, text);
}
Expand Down
7 changes: 7 additions & 0 deletions HtmlDiff/HtmlDiff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>HtmlDiffPublicPrivate.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
Expand Down Expand Up @@ -66,6 +72,7 @@
<None Include="HtmlDiff.nuspec">
<SubType>Designer</SubType>
</None>
<None Include="HtmlDiffPublicPrivate.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Binary file added HtmlDiff/HtmlDiffPublicPrivate.snk
Binary file not shown.
4 changes: 2 additions & 2 deletions HtmlDiff/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3")]
[assembly: AssemblyFileVersion("1.3")]
[assembly: AssemblyVersion("1.3.1")]
[assembly: AssemblyFileVersion("1.3.1")]
Binary file added HtmlDiff/htmldiff.net.1.3.1.nupkg
Binary file not shown.
66 changes: 66 additions & 0 deletions Test.HtmlDiff/HtmlDiffSpecTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,71 @@ public void Execute_WithGroupCandididatesAndDuplicateGroupsConfigured_ArgumentEx
var ex = Assert.Throws<ArgumentException>(() => diff.Build());
Assert.IsTrue(ex.Message.EndsWith(pattern));
}


#region NewOptions

[TestCase(
"one a word is somewhere",
"a word is somewhere",
"a word is somewhere")]

[TestCase(
"one a word is somewhere",
"two a word is somewhere",
"<ins class='diffmod'>two</ins> a word is somewhere")]
public void Execute_WithIgnoreDelete_OutputVerified(string oldText, string newText, string delta)
{
Debug.WriteLine("Old text: " + oldText);
Debug.WriteLine("New text: " + newText);
Debug.WriteLine("");
Debug.WriteLine("Expected Diff: " + delta);
var diff = new global::HtmlDiff.HtmlDiff(oldText, newText){ IgnoreDelete = true};
var result = diff.Build();
Debug.WriteLine("");
Debug.WriteLine("Actual Diff: " + result);
Assert.AreEqual(delta, result);
}

[TestCase(
"a word is somewhere",
"one a word is somewhere",
"one a word is somewhere")]

[TestCase(
"one a word is somewhere",
"two a word is somewhere",
"<del class='diffmod'>one</del>two a word is somewhere")]
public void Execute_WithIgnoreInsert_OutputVerified(string oldText, string newText, string delta)
{
Debug.WriteLine("Old text: " + oldText);
Debug.WriteLine("New text: " + newText);
Debug.WriteLine("");
Debug.WriteLine("Expected Diff: " + delta);
var diff = new global::HtmlDiff.HtmlDiff(oldText, newText){ IgnoreInsert = true };
var result = diff.Build();
Debug.WriteLine("");
Debug.WriteLine("Actual Diff: " + result);
Assert.AreEqual(delta, result);
}

[TestCase(
"one a word is somewhere",
"two a texts is somewhere",
"two a texts is somewhere")]
public void Execute_WithIgnoreDeleteAndIgnoreInsert_OutputVerified(string oldText, string newText, string delta)
{
Debug.WriteLine("Old text: " + oldText);
Debug.WriteLine("New text: " + newText);
Debug.WriteLine("");
Debug.WriteLine("Expected Diff: " + delta);
var diff = new global::HtmlDiff.HtmlDiff(oldText, newText){ IgnoreDelete = true, IgnoreInsert = true };
var result = diff.Build();
Debug.WriteLine("");
Debug.WriteLine("Actual Diff: " + result);
Assert.AreEqual(delta, result);
}

#endregion
}
}