Skip to content

Commit 6feca8a

Browse files
author
Thomas Hambach
committed
Added unit tests to patches.
1 parent f2f64f1 commit 6feca8a

File tree

17 files changed

+785
-45
lines changed

17 files changed

+785
-45
lines changed

.vscode/launch.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/CSharpDiff.Tests/bin/Debug/net6.0/CSharpDiff.Tests.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/CSharpDiff.Tests",
16+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17+
"console": "internalConsole",
18+
"stopAtEntry": false
19+
},
20+
{
21+
"name": ".NET Core Attach",
22+
"type": "coreclr",
23+
"request": "attach"
24+
}
25+
]
26+
}

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"source.fixAll": false,
55
"source.organizeImports": true,
66
"source.sortMembers": true
7-
}
7+
},
8+
"editor.formatOnSave": true,
9+
"omnisharp.enableImportCompletion": true
810
}

.vscode/tasks.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/CSharpDiff.Tests/CSharpDiff.Tests.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/CSharpDiff.Tests/CSharpDiff.Tests.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/CSharpDiff.Tests/CSharpDiff.Tests.csproj"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}

CSharpDiff.Tests/DiffWordTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using CSharpDiff.Converters;
2+
using CSharpDiff.Diffs;
3+
4+
namespace CSharpDiff.Tests
5+
{
6+
7+
public class DiffWordTests
8+
{
9+
[Fact]
10+
public void ShouldDiffWhitespace()
11+
{
12+
var diff = new DiffWord();
13+
var diffResult = diff.diff("New Value", "New ValueMoreData");
14+
var converted = DiffConvertXml.Convert(diffResult);
15+
Assert.Equal("New <del>Value</del><ins>ValueMoreData</ins>", converted);
16+
}
17+
18+
[Fact]
19+
public void ShouldDiffMultipleWhitespace()
20+
{
21+
var diff = new DiffWord();
22+
var diffResult = diff.diff("New Value ", "New ValueMoreData ");
23+
var converted = DiffConvertXml.Convert(diffResult);
24+
Assert.Equal("New <del>Value</del><ins>ValueMoreData</ins> ", converted);
25+
}
26+
27+
28+
[Fact]
29+
public void ShouldDiffOnWordBoundaries()
30+
{
31+
var diff = new DiffWord();
32+
var diffResult = diff.diff("New :Value:Test", "New ValueMoreData ");
33+
var converted = DiffConvertXml.Convert(diffResult);
34+
Assert.Equal("New <del>:Value:Test</del><ins>ValueMoreData </ins>", converted);
35+
36+
// @todo Tests below still bug out due to the REGEX in DiffWord.Tokenize
37+
// diffResult = diff.diff("New Value:Test", "New Value:MoreData ");
38+
// converted = DiffConvertXml.Convert(diffResult);
39+
// Assert.Equal("New Value:<del>Test</del><ins>MoreData </ins>", converted);
40+
41+
// diffResult = diff.diff("New Value-Test", "New Value:MoreData ");
42+
// converted = DiffConvertXml.Convert(diffResult);
43+
// Assert.Equal("New Value<del>-Test</del><ins>:MoreData </ins>", converted);
44+
45+
// diffResult = diff.diff("New Value", "New Value:MoreData ");
46+
// converted = DiffConvertXml.Convert(diffResult);
47+
// Assert.Equal("New Value<del>-Test</del><ins>:MoreData </ins>", converted);
48+
}
49+
50+
[Fact]
51+
public void ShouldHandleIdentity()
52+
{
53+
// var diff = new DiffWord();
54+
// var diffResult = diff.diff("New Value", "New Value");
55+
// var converted = DiffConvertXml.Convert(diffResult);
56+
// Assert.Equal("New Value", converted);
57+
}
58+
59+
}
60+
}

0 commit comments

Comments
 (0)