powershell-es/test/PowerShellEditorServices.Test/Session/PathEscapingTests.cs
fwastring baa0056244
Some checks are pending
CI Tests / dotnet (push) Waiting to run
CI Tests / dotnet-1 (push) Waiting to run
CI Tests / dotnet-2 (push) Waiting to run
Emacs End-to-End Tests / ert (push) Waiting to run
Vim End-to-End Tests / themis (push) Waiting to run
initial
2026-02-17 13:06:31 +01:00

53 lines
3.1 KiB
C#

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Xunit;
using Microsoft.PowerShell.EditorServices.Utility;
namespace PowerShellEditorServices.Test.Session
{
public class PathEscapingTests
{
[Trait("Category", "PathEscaping")]
[Theory]
[InlineData("DebugTest.ps1", "DebugTest.ps1")]
[InlineData("../../DebugTest.ps1", "../../DebugTest.ps1")]
[InlineData(@"C:\Users\me\Documents\DebugTest.ps1", @"C:\Users\me\Documents\DebugTest.ps1")]
[InlineData("/home/me/Documents/weird&folder/script.ps1", "/home/me/Documents/weird&folder/script.ps1")]
[InlineData("./path/with some/spaces", "./path/with some/spaces")]
[InlineData(@"C:\path\with[some]brackets\file.ps1", @"C:\path\with`[some`]brackets\file.ps1")]
[InlineData(@"C:\look\an*\here.ps1", @"C:\look\an`*\here.ps1")]
[InlineData("/Users/me/Documents/?here.ps1", "/Users/me/Documents/`?here.ps1")]
[InlineData("/Brackets [and s]paces/path.ps1", "/Brackets `[and s`]paces/path.ps1")]
[InlineData("/CJK.chars/脚本/hello.ps1", "/CJK.chars/脚本/hello.ps1")]
[InlineData("/CJK.chars/脚本/[hello].ps1", "/CJK.chars//`[hello`].ps1")]
[InlineData(@"C:\Animals\утка\quack.ps1", @"C:\Animals\утка\quack.ps1")]
[InlineData(@"C:\&nimals\утка\qu*ck?.ps1", @"C:\&nimals\утка\qu`*ck`?.ps1")]
public void CorrectlyWildcardEscapesPathsNoSpaces(string unescapedPath, string escapedPath)
{
string extensionEscapedPath = PathUtils.WildcardEscapePath(unescapedPath);
Assert.Equal(escapedPath, extensionEscapedPath);
}
[Trait("Category", "PathEscaping")]
[Theory]
[InlineData("DebugTest.ps1", "DebugTest.ps1")]
[InlineData("../../DebugTest.ps1", "../../DebugTest.ps1")]
[InlineData(@"C:\Users\me\Documents\DebugTest.ps1", @"C:\Users\me\Documents\DebugTest.ps1")]
[InlineData("/home/me/Documents/weird&folder/script.ps1", "/home/me/Documents/weird&folder/script.ps1")]
[InlineData("./path/with some/spaces", "./path/with` some/spaces")]
[InlineData(@"C:\path\with[some]brackets\file.ps1", @"C:\path\with`[some`]brackets\file.ps1")]
[InlineData(@"C:\look\an*\here.ps1", @"C:\look\an`*\here.ps1")]
[InlineData("/Users/me/Documents/?here.ps1", "/Users/me/Documents/`?here.ps1")]
[InlineData("/Brackets [and s]paces/path.ps1", "/Brackets` `[and` s`]paces/path.ps1")]
[InlineData("/CJK chars/脚本/hello.ps1", "/CJK` chars/脚本/hello.ps1")]
[InlineData("/CJK chars/脚本/[hello].ps1", "/CJK` chars//`[hello`].ps1")]
[InlineData(@"C:\Animal s\утка\quack.ps1", @"C:\Animal` s\утка\quack.ps1")]
[InlineData(@"C:\&nimals\утка\qu*ck?.ps1", @"C:\&nimals\утка\qu`*ck`?.ps1")]
public void CorrectlyWildcardEscapesPathsSpaces(string unescapedPath, string escapedPath)
{
string extensionEscapedPath = PathUtils.WildcardEscapePath(unescapedPath, escapeSpaces: true);
Assert.Equal(escapedPath, extensionEscapedPath);
}
}
}