-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
HunkRangeInfoTests.cs
117 lines (90 loc) · 4 KB
/
HunkRangeInfoTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#region using
using System.Collections.Generic;
using GitDiffMargin.Git;
using NUnit.Framework;
using Shouldly;
#endregion
namespace GitDiffMargin.Unit.Tests.Git
{
// ReSharper disable InconsistentNaming
[TestFixture(0)]
public class HunkRangeInfoTests
{
public HunkRangeInfoTests(int contextLines)
{
_contextLines = contextLines;
}
private readonly int _contextLines = 0;
[Test]
public void IsAddition_AllDiffLinesWithStartsWithPlusSign_ExpectedTrue()
{
//Arrange
var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List<string> { "+ ", "+ " }.ToArray());
//Act
bool isAddition = hunkRangeInfo.IsAddition;
//Assert
isAddition.ShouldBe(true);
}
[Test]
public void IsAddition_NotAllDiffLinesStartsWithPlusSign_ExpectedFalse()
{
//Arrange
var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List<string> { "+ ", "- " }.ToArray());
//Act
bool isAddition = hunkRangeInfo.IsAddition;
//Assert
isAddition.ShouldBe(false);
}
[Test]
public void IsModification_DiffLinesStartsWithPlusSignAndWithMinus_ExpectedTrue()
{
//Arrange
var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List<string> { "+ ", "- " }.ToArray());
//Act
bool isModification = hunkRangeInfo.IsModification;
//Assert
isModification.ShouldBe(true);
}
[Test]
public void OriginalText_1NewLineAnd1OriginalLine_ExpectedOriginalText()
{
//Arrange
var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List<string> { "+New Text", "-Original Text" }.ToArray());
//Act
string originalText = hunkRangeInfo.OriginalText[0];
//Assert
originalText.ShouldBe("Original Text");
}
[Test]
public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpaces_ExpectedOriginalText()
{
//Arrange
var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List<string> { "+ New Text", "- Original Text" }.ToArray());
//Act
string originalText = hunkRangeInfo.OriginalText[0];
//Assert
originalText.ShouldBe(" Original Text");
}
[Test]
public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpacesAndInvertedOrder_ExpectedOriginalText()
{
//Arrange
var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-18", _contextLines), new HunkRange("+18", _contextLines), new List<string> { "- it++; // this is just a comment", "+ it--;" }.ToArray());
//Act
var originalText = hunkRangeInfo.OriginalText;
//Assert
originalText[0].ShouldBe(" it++; // this is just a comment");
}
[Test]
public void IsDeletion_3DeletedLines_ExpectTrue()
{
//Arrange
var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-7,3", _contextLines), new HunkRange("+6,0", _contextLines), new List<string> { "-using Microsoft.VisualStudio.Shell;", "-using Microsoft.VisualStudio.Text;", "-using Microsoft.VisualStudio.Text.Editor;" }.ToArray());
//Act
var isDeletion = hunkRangeInfo.IsDeletion;
//Assert
isDeletion.ShouldBe(true);
}
}
// ReSharper restore InconsistentNaming
}