mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[PowerToys Run] Add Suport for Commandline arguments in Program Plugin (#5791)
* Implemented possibility to add commandline arguments in the Program Plugin * Add missing return statement inc ommandArgumentParser loop * Fix typos * Fix Additional Typo * Changed -c to /c to make it a valid cmd argument * Added small comment about importance of order in _programArgumentParsers Co-authored-by: Roy <royvou@hotmailcom>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Plugin.Program.ProgramArgumentParser;
|
||||
using NUnit.Framework;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Microsoft.Plugin.Program.UnitTests.ProgramArgumentParser
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProgramArgumentParserTests
|
||||
{
|
||||
[TestCase("Microsoft Edge", "Microsoft Edge", null)]
|
||||
[TestCase("Microsoft Edge ---inprivate", "Microsoft Edge ---inprivate", null)]
|
||||
[TestCase("Microsoft Edge -- -inprivate", "Microsoft Edge", "-inprivate")]
|
||||
[TestCase("Microsoft Edge -inprivate", "Microsoft Edge", "-inprivate")]
|
||||
[TestCase("Microsoft Edge /inprivate", "Microsoft Edge", "/inprivate")]
|
||||
[TestCase("edge.exe --inprivate", "edge.exe", "--inprivate")]
|
||||
[TestCase("edge.exe -- --inprivate", "edge.exe", "--inprivate")]
|
||||
[TestCase("edge.exe", "edge.exe", null)]
|
||||
[TestCase("edge", "edge", null)]
|
||||
[TestCase("cmd /c \"ping 1.1.1.1\"", "cmd", "/c \"ping 1.1.1.1\"")]
|
||||
public void ProgramArgumentParserTestsCanParseQuery(string inputQuery, string expectedProgram, string expectedProgramArguments)
|
||||
{
|
||||
// Arrange
|
||||
var argumentParsers = new IProgramArgumentParser[]
|
||||
{
|
||||
new DoubleDashProgramArgumentParser(),
|
||||
new InferedProgramArgumentParser(),
|
||||
new NoArgumentsArgumentParser(),
|
||||
};
|
||||
|
||||
// basic version of the Quey parser which can be found at Wox.Core.Plugin.QueryBuilder but did not want to create a project reference
|
||||
var splittedSearchString = inputQuery?.Split(Query.TermSeparator, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
var cleanQuery = string.Join(Query.TermSeparator, splittedSearchString);
|
||||
var query = new Query(cleanQuery, cleanQuery, splittedSearchString, string.Empty);
|
||||
|
||||
// Act
|
||||
string program = null, programArguments = null;
|
||||
foreach (var argumentParser in argumentParsers)
|
||||
{
|
||||
if (argumentParser.TryParse(query, out program, out programArguments))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expectedProgram, program);
|
||||
Assert.AreEqual(expectedProgramArguments, programArguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -547,7 +547,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
StringMatcher.Instance = new StringMatcher();
|
||||
|
||||
// Act
|
||||
var result = _cmderRunCommand.Result("cmder", mock.Object);
|
||||
var result = _cmderRunCommand.Result("cmder", string.Empty, mock.Object);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result.Title.Equals(_cmderRunCommand.Name, StringComparison.Ordinal));
|
||||
|
||||
Reference in New Issue
Block a user