mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add tests for checking string is location path
This commit is contained in:
parent
06667b7aa7
commit
78b797e43b
2 changed files with 66 additions and 4 deletions
|
|
@ -104,7 +104,7 @@ namespace Flow.Launcher.Test.Plugins
|
|||
public void GivenWindowsIndexSearch_WhenReturnedZeroResultsAndIsNotIndexed_ThenSearchMethodShouldContinueDirectoryInfoClassSearch()
|
||||
{
|
||||
// Given
|
||||
var searchManager = new SearchManager();
|
||||
var searchManager = new SearchManager(new Settings(), new PluginInitContext());
|
||||
|
||||
// When
|
||||
var results = searchManager.TopLevelFolderSearch(
|
||||
|
|
@ -123,7 +123,7 @@ namespace Flow.Launcher.Test.Plugins
|
|||
public void GivenWindowsIndexSearch_WhenReturnedZeroResultsAndIsIndexed_ThenSearchMethodShouldNotContinueDirectoryInfoClassSearch()
|
||||
{
|
||||
// Given
|
||||
var searchManager = new SearchManager();
|
||||
var searchManager = new SearchManager(new Settings(), new PluginInitContext());
|
||||
|
||||
// When
|
||||
var results = searchManager.TopLevelFolderSearch(
|
||||
|
|
@ -139,5 +139,25 @@ namespace Flow.Launcher.Test.Plugins
|
|||
}
|
||||
|
||||
public void GivenWindowsIndexSearch_WhenSearchPatternHotKeyIsSearchAll_ThenQueryWhereRestrictionsShouldUseScopeString() { }
|
||||
|
||||
[TestCase(@"c:\\", false)]
|
||||
[TestCase(@"i:\", true)]
|
||||
[TestCase(@"\c:\", false)]
|
||||
[TestCase(@"cc:\", false)]
|
||||
[TestCase(@"\\\SomeNetworkLocation\", false)]
|
||||
[TestCase("RandomString", false)]
|
||||
public void WhenGivenQuerySearchString_ThenShouldIndicateIfItIsLocationString(string querySearchString, bool expectedResult)
|
||||
{
|
||||
// When, Given
|
||||
var searchManager = new SearchManager(new Settings(), new PluginInitContext());
|
||||
|
||||
var result = searchManager.IsLocationPathString(querySearchString);
|
||||
|
||||
//Then
|
||||
Assert.IsTrue(result == expectedResult,
|
||||
$"Expected query search string check result is: {expectedResult} {Environment.NewLine} " +
|
||||
$"Actual check result is {result} {Environment.NewLine}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,53 @@
|
|||
using System;
|
||||
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Explorer.Search
|
||||
{
|
||||
public class SearchManager
|
||||
{
|
||||
private Settings _settings;
|
||||
private PluginInitContext _context;
|
||||
|
||||
public SearchManager(Settings settings, PluginInitContext context)
|
||||
{
|
||||
_settings = settings;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// This checks whether a given string is a directory path or network location string.
|
||||
/// It does not check if location actually exists.
|
||||
///</summary>
|
||||
public bool IsLocationPathString(string querySearchString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(querySearchString))
|
||||
return false;
|
||||
|
||||
// // shared folder location, and not \\\location\
|
||||
if (querySearchString.Length >= 3
|
||||
&& querySearchString.StartsWith(@"\\")
|
||||
&& char.IsLetter(querySearchString[2]))
|
||||
return true;
|
||||
|
||||
// c:\
|
||||
if (querySearchString.Length == 3
|
||||
&& char.IsLetter(querySearchString[0])
|
||||
&& querySearchString[1] == ':'
|
||||
&& querySearchString[2] == '\\')
|
||||
return true;
|
||||
|
||||
// c:\\
|
||||
if (querySearchString.Length >= 4
|
||||
&& char.IsLetter(querySearchString[0])
|
||||
&& querySearchString[1] == ':'
|
||||
&& querySearchString[2] == '\\'
|
||||
&& char.IsLetter(querySearchString[3]))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Result> TopLevelFolderSearch(
|
||||
Func<string, List<Result>> windowsIndexSearch,
|
||||
Func<string, List<Result>> directoryInfoClassSearch,
|
||||
|
|
|
|||
Loading…
Reference in a new issue