forked from VsVim/VsVim
/
WordUtilTest.cs
129 lines (117 loc) · 4.35 KB
/
WordUtilTest.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
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Linq;
using EditorUtils.UnitTest;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using NUnit.Framework;
namespace Vim.UnitTest
{
[TestFixture]
public sealed class WordUtilTest : VimTestBase
{
private ITextBuffer _textBuffer;
private ITextView _textView;
private IWordUtil _wordUtil;
private WordUtil _wordUtilRaw;
[TearDown]
public void TearDown()
{
_textBuffer = null;
}
private void Create(params string[] lines)
{
Create(0, lines);
}
private void Create(int caretPosition, params string[] lines)
{
_textView = CreateTextView(lines);
_textBuffer = _textView.TextBuffer;
_wordUtilRaw = new WordUtil(_textBuffer, CreateTextStructureNavigator(_textBuffer, WordKind.NormalWord));
_wordUtil = _wordUtilRaw;
}
/// <summary>
/// Break up the buffer into simple words
/// </summary>
[Test]
public void GetWords_Normal()
{
Create("dog ca$$t $b");
var ret = _wordUtil.GetWords(WordKind.NormalWord, Path.Forward, _textBuffer.GetPoint(0));
CollectionAssert.AreEquivalent(
new[] { "dog", "ca", "$$", "t", "$", "b" },
ret.Select(x => x.GetText()).ToList());
}
/// <summary>
/// A blank line should be a word
/// </summary>
[Test]
public void GetWords_BlankLine()
{
Create("dog cat", "", "bear");
var ret = _wordUtil.GetWords(WordKind.NormalWord, Path.Forward, _textBuffer.GetPoint(0));
CollectionAssert.AreEquivalent(
new[] { "dog", "cat", Environment.NewLine, "bear" },
ret.Select(x => x.GetText()).ToList());
}
/// <summary>
/// From the middle of a word should return the span of the entire word
/// </summary>
[Test]
public void GetWords_FromMiddleOfWord()
{
Create("dog cat");
var ret = _wordUtil.GetWords(WordKind.NormalWord, Path.Forward, _textBuffer.GetPoint(1));
CollectionAssert.AreEquivalent(
new[] { "dog", "cat" },
ret.Select(x => x.GetText()).ToList());
}
/// <summary>
/// From the end of a word should return the span of the entire word
/// </summary>
[Test]
public void GetWords_FromEndOfWord()
{
Create("dog cat");
var ret = _wordUtil.GetWords(WordKind.NormalWord, Path.Forward, _textBuffer.GetPoint(2));
CollectionAssert.AreEquivalent(
new[] { "dog", "cat" },
ret.Select(x => x.GetText()).ToList());
}
/// <summary>
/// From the middle of a word backward
/// </summary>
[Test]
public void GetWords_BackwardFromMiddle()
{
Create("dog cat");
var ret = _wordUtil.GetWords(WordKind.NormalWord, Path.Backward, _textBuffer.GetPoint(5));
CollectionAssert.AreEquivalent(
new[] { "cat", "dog" },
ret.Select(x => x.GetText()).ToList());
}
/// <summary>
/// From the start of a word backward should not include that particular word
/// </summary>
[Test]
public void GetWords_BackwardFromStart()
{
Create("dog cat");
var ret = _wordUtil.GetWords(WordKind.NormalWord, Path.Backward, _textBuffer.GetPoint(4));
CollectionAssert.AreEquivalent(
new[] { "dog" },
ret.Select(x => x.GetText()).ToList());
}
/// <summary>
/// Make sure that blank lines are counted as words when
/// </summary>
[Test]
public void GetWords_BackwardBlankLine()
{
Create("dog", "", "cat");
var ret = _wordUtil.GetWords(WordKind.NormalWord, Path.Backward, _textBuffer.GetLine(2).Start.Add(1));
CollectionAssert.AreEquivalent(
new[] { "cat", Environment.NewLine, "dog" },
ret.Select(x => x.GetText()).ToList());
}
}
}