This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 770
/
IndexBeforeTextFinderTests.cs
70 lines (58 loc) · 2.33 KB
/
IndexBeforeTextFinderTests.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
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Dom.Tests.NUnitHelpers;
using NUnit.Framework;
namespace ICSharpCode.SharpDevelop.Dom.Tests
{
[TestFixture]
public class IndexBeforeTextFinderTests
{
TextFinder textFinder;
IndexBeforeTextFinderHelper helper;
void CreateIndexBeforeTextFinderWithSearchTextOf(string searchText)
{
helper = new IndexBeforeTextFinderHelper();
textFinder = helper.CreateIndexBeforeTextFinder(searchText);
}
void AssertTextFindMatchesAreEqual(TextFinderMatch expectedMatch, TextFinderMatch actualMatch)
{
string expectedMatchAsString = GetTextFinderMatchAsString(expectedMatch);
string actualMatchAsString = GetTextFinderMatchAsString(actualMatch);
Assert.AreEqual(expectedMatchAsString, actualMatchAsString);
}
string GetTextFinderMatchAsString(TextFinderMatch match)
{
return String.Format(
"Position: {0}, Length: {1}, ResolvePosition: {2}",
match.Position,
match.Length,
match.ResolvePosition);
}
[Test]
public void Find_SearchingForSquareBracketCharacterAndInputTextHasNoSquareBracketCharacter_ReturnsEmptyTextFinderMatch()
{
CreateIndexBeforeTextFinderWithSearchTextOf("[");
TextFinderMatch match = textFinder.Find("abc", 0);
AssertTextFindMatchesAreEqual(TextFinderMatch.Empty, match);
}
[Test]
public void Find_SearchingForSquareBracketCharacterAndInputTextHasSquareBracketAtPositionOne_ReturnsTextFinderMatchForPositionOne()
{
CreateIndexBeforeTextFinderWithSearchTextOf("[");
TextFinderMatch match = textFinder.Find("a[0]", 0);
TextFinderMatch expectedMatch =
new TextFinderMatch(position: 1, length: 1, resolvePosition: 0);
AssertTextFindMatchesAreEqual(expectedMatch, match);
}
[Test]
public void Find_SearchingForSquareBracketCharacterAndInputTextHasSquareBracketCharacterAtPositionZero_ReturnsEmptyTextFinderMatch()
{
CreateIndexBeforeTextFinderWithSearchTextOf("[");
TextFinderMatch match = textFinder.Find("[assembly: AssemblyCulture(\"\")]", 0);
AssertTextFindMatchesAreEqual(TextFinderMatch.Empty, match);
}
}
}