Repository navigation
Expand file tree
/
Copy pathBlockCommentTests.cs
More file actions
164 lines (138 loc) · 5.79 KB
/
Copy pathBlockCommentTests.cs
File metadata and controls
164 lines (138 loc) · 5.79 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Actions;
using ICSharpCode.TextEditor.Document;
using NUnit.Framework;
using System;
namespace ICSharpCode.TextEditor.Tests
{
[TestFixture]
public class BlockCommentTests
{
IDocument document = null;
string commentStart = "<!--";
string commentEnd = "-->";
[SetUp]
public void Init()
{
document = new DocumentFactory().CreateDocument();
document.HighlightingStrategy = HighlightingManager.Manager.FindHighlighter("XML");
}
[Test]
public void NoTextSelected()
{
document.TextContent = String.Empty;
int selectionStartOffset = 0;
int selectionEndOffset = 0;
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.IsNull(commentRegion, "Should not be a comment region for an empty document");
}
[Test]
public void EntireCommentSelected()
{
document.TextContent = "<!---->";
int selectionStartOffset = 0;
int selectionEndOffset = 7;
BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 4);
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.AreEqual(expectedCommentRegion, commentRegion);
}
[Test]
public void EntireCommentAndExtraTextSelected()
{
document.TextContent = "a<!-- -->";
int selectionStartOffset = 0;
int selectionEndOffset = 9;
BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 1, 6);
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.AreEqual(expectedCommentRegion, commentRegion);
}
[Test]
public void OnlyCommentStartSelected()
{
document.TextContent = "<!-- -->";
int selectionStartOffset = 0;
int selectionEndOffset = 4;
BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 5);
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.AreEqual(expectedCommentRegion, commentRegion);
}
[Test]
public void OnlyCommentEndSelected()
{
document.TextContent = "<!-- -->";
int selectionStartOffset = 5;
int selectionEndOffset = 8;
BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 5);
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.AreEqual(expectedCommentRegion, commentRegion);
}
[Test]
public void LastCharacterOfCommentEndSelected()
{
document.TextContent = "<!-- -->";
int selectionStartOffset = 7;
int selectionEndOffset = 8;
BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 5);
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.AreEqual(expectedCommentRegion, commentRegion);
}
[Test]
public void CaretInsideCommentButNoSelectedText()
{
document.TextContent = "<!---->";
int selectionStartOffset = 4;
int selectionEndOffset = 4;
BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 4);
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.AreEqual(expectedCommentRegion, commentRegion);
}
[Test]
public void FirstCharacterOfCommentStartSelected()
{
document.TextContent = "<!-- -->";
int selectionStartOffset = 0;
int selectionEndOffset = 1;
BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 5);
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.AreEqual(expectedCommentRegion, commentRegion);
}
[Test]
public void CursorJustOutsideCommentStart()
{
document.TextContent = "<!-- -->";
int selectionStartOffset = 0;
int selectionEndOffset = 0;
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.IsNull(commentRegion);
}
[Test]
public void CursorJustOutsideCommentEnd()
{
document.TextContent = "<!-- -->";
int selectionStartOffset = 8;
int selectionEndOffset = 8;
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.IsNull(commentRegion);
}
[Test]
public void TwoExistingBlockComments()
{
document.TextContent = "<a>\r\n" +
"<!--<b></b>-->\r\n" +
"\t<c></c>\r\n" +
"<!--<d></d>-->\r\n" +
"</a>";
string selectedText = "<c></c>";
int selectionStartOffset = document.TextContent.IndexOf(selectedText);
int selectionEndOffset = selectionStartOffset + selectedText.Length;
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.IsNull(commentRegion);
}
}
}