Flow.Launcher/Flow.Launcher.Test/QueryBuilderTest.cs

65 lines
2.7 KiB
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using NUnit.Framework;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Plugin;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Test
{
public class QueryBuilderTest
{
[Test]
public void ExclusivePluginQueryTest()
{
var nonGlobalPlugins = new Dictionary<string, PluginPair>
{
{">", new PluginPair {Metadata = new PluginMetadata {ActionKeywords = new List<string> {">"}}}}
};
2023-06-24 14:30:15 +00:00
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins);
2023-06-24 14:30:15 +00:00
Assert.AreEqual("> ping google.com -n 20 -6", q.RawQuery);
Assert.AreEqual("ping google.com -n 20 -6", q.Search, "Search should not start with the ActionKeyword.");
Assert.AreEqual(">", q.ActionKeyword);
2023-06-24 14:30:15 +00:00
Assert.AreEqual(5, q.SearchTerms.Length, "The length of SearchTerms should match.");
Assert.AreEqual("ping", q.FirstSearch);
Assert.AreEqual("google.com", q.SecondSearch);
Assert.AreEqual("-n", q.ThirdSearch);
Assert.AreEqual("google.com -n 20 -6", q.SecondToEndSearch, "SecondToEndSearch should be trimmed of multiple whitespace characters");
}
[Test]
public void ExclusivePluginQueryIgnoreDisabledTest()
{
var nonGlobalPlugins = new Dictionary<string, PluginPair>
{
{">", new PluginPair {Metadata = new PluginMetadata {ActionKeywords = new List<string> {">"}, Disabled = true}}}
};
2023-06-24 14:30:15 +00:00
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins);
2023-06-24 14:30:15 +00:00
Assert.AreEqual("> ping google.com -n 20 -6", q.Search);
Assert.AreEqual(q.Search, q.RawQuery, "RawQuery should be equal to Search.");
Assert.AreEqual(6, q.SearchTerms.Length, "The length of SearchTerms should match.");
Assert.AreNotEqual(">", q.ActionKeyword, "ActionKeyword should not match that of a disabled plugin.");
Assert.AreEqual("ping google.com -n 20 -6", q.SecondToEndSearch, "SecondToEndSearch should be trimmed of multiple whitespace characters");
}
[Test]
public void GenericPluginQueryTest()
{
Query q = QueryBuilder.Build("file.txt file2 file3", new Dictionary<string, PluginPair>());
Assert.AreEqual("file.txt file2 file3", q.Search);
Assert.AreEqual("", q.ActionKeyword);
Assert.AreEqual("file.txt", q.FirstSearch);
Assert.AreEqual("file2", q.SecondSearch);
Assert.AreEqual("file3", q.ThirdSearch);
Assert.AreEqual("file2 file3", q.SecondToEndSearch);
}
}
}