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