📄 searchstrategytest.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version value="$version"/>
// </file>
using System;
using System.Text;
using ICSharpCode.Core.Properties;
using ICSharpCode.SharpUnit;
using ICSharpCode.TextEditor.Document;
[TestSuiteAttribute()]
public class SearchStrategyTests
{
void TestStrategy(ISearchStrategy searchStrategy)
{
IDocumentAggregator document = new DocumentAggregatorFactory().CreateDocument();
string testText = "1234567890\n" +
"123456789\n" +
"12345678\n" +
"1234567\n" +
"123456\n" +
"12345\n" +
"123n\n" +
"12\n" +
"1\n" +
"urrentOffs frefr ergf roeihore reuhfreu rehffrh FOKew(q ew jfew (ergre )()GREgrggre" +
"hallo";
document.TextContent = testText;
SearchOptions options = new SearchOptions(new DefaultProperties());
options.SearchPattern = "123n";
searchStrategy.CompilePattern(options);
ISearchResult location = searchStrategy.FindNext(new ForwardTextIterator(document.TextBufferStrategy, 0), options);
Assertion.AssertEquals(51, location.Offset);
options.SearchPattern = "12";
searchStrategy.CompilePattern(options);
location = searchStrategy.FindNext(new ForwardTextIterator(document.TextBufferStrategy, location.Offset + location.Length), options);
Assertion.AssertEquals(56, location.Offset);
options.SearchPattern = "frefre";
options.IgnoreCase = true;
searchStrategy.CompilePattern(options);
location = searchStrategy.FindNext(new ForwardTextIterator(document.TextBufferStrategy, 0), options);
Assertion.AssertNull("Search strategy found ghost pattern", location);
options.SearchPattern = "n";
searchStrategy.CompilePattern(options);
location = searchStrategy.FindNext(new ForwardTextIterator(document.TextBufferStrategy, 0), options);
Assertion.AssertEquals(54, location.Offset);
options.SearchPattern = "hallo12345";
searchStrategy.CompilePattern(options);
location = searchStrategy.FindNext(new ForwardTextIterator(document.TextBufferStrategy, 10), options);
Assertion.AssertNull("Search strategy didn't recognize file end", location);
}
[TestMethodAttribute()]
public void TestBasicKMPSearch()
{
TestStrategy(new KMPSearchStrategy());
}
[TestMethodAttribute()]
public void TestBasicWildcardSearch()
{
TestStrategy(new WildcardSearchStrategy());
}
[TestMethodAttribute()]
public void TestBasicRegExSearch()
{
TestStrategy(new RegExSearchStrategy());
}
[TestMethodAttribute()]
public void TestBasicBruteForceSearch()
{
TestStrategy(new BruteForceSearchStrategy());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -