Skip to content

Commit

Permalink
Use verbatim strings in tests' file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Sep 7, 2023
1 parent c60d8d4 commit 9e19755
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Dispose()
[Fact]
public async Task CanRegisterAndInvokeCommandWithCmdletName()
{
string filePath = TestUtilities.NormalizePath("C:\\Temp\\Test.ps1");
string filePath = TestUtilities.NormalizePath(@"C:\Temp\Test.ps1");
ScriptFile currentFile = new(new Uri(filePath), "This is a test file", new Version("7.0"));
EditorContext editorContext = new(
editorOperations: null,
Expand Down Expand Up @@ -87,7 +87,7 @@ await psesHost.ExecutePSCommandAsync(
[Fact]
public async Task CanRegisterAndInvokeCommandWithScriptBlock()
{
string filePath = TestUtilities.NormalizePath("C:\\Temp\\Test.ps1");
string filePath = TestUtilities.NormalizePath(@"C:\Temp\Test.ps1");
ScriptFile currentFile = new(new Uri(filePath), "This is a test file", new Version("7.0"));
EditorContext editorContext = new(
editorOperations: null,
Expand Down Expand Up @@ -149,7 +149,7 @@ await psesHost.ExecutePSCommandAsync(
[Fact]
public async Task CanUnregisterCommand()
{
string filePath = TestUtilities.NormalizePath("C:\\Temp\\Test.ps1");
string filePath = TestUtilities.NormalizePath(@"C:\Temp\Test.ps1");
ScriptFile currentFile = new(new Uri(filePath), "This is a test file", new Version("7.0"));
EditorContext editorContext = new(
editorOperations: null,
Expand Down
20 changes: 10 additions & 10 deletions test/PowerShellEditorServices.Test/Session/PathEscapingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public class PathEscapingTests
[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(@"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(@"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")]
[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);
Expand All @@ -33,17 +33,17 @@ public void CorrectlyWildcardEscapesPathsNoSpaces(string unescapedPath, string e
[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(@"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(@"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")]
[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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ await psesHost.ExecutePSCommandAsync(

[Theory]
[InlineData("")] // Regression test for "unset" path.
[InlineData("C:\\Some\\Bad\\Directory")] // Non-existent directory.
[InlineData(@"C:\Some\Bad\Directory")] // Non-existent directory.
[InlineData("testhost.dll")] // Existent file.
public async Task CanHandleBadInitialWorkingDirectory(string path)
{
Expand Down
7 changes: 4 additions & 3 deletions test/PowerShellEditorServices.Test/Session/ScriptFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,20 +654,21 @@ public void DocumentUriReturnsCorrectStringForAbsolutePath()
scriptFile = new ScriptFile(DocumentUri.FromFileSystemPath(path), emptyStringReader, PowerShellVersion);
Assert.Equal("file:///home/NaomiNagata/projects/Rocinate/Proto%3AMole%3Acule.ps1", scriptFile.DocumentUri);

path = "/home/JamesHolden/projects/Rocinate/Proto:Mole\\cule.ps1";
path = @"/home/JamesHolden/projects/Rocinate/Proto:Mole\cule.ps1";
scriptFile = new ScriptFile(DocumentUri.FromFileSystemPath(path), emptyStringReader, PowerShellVersion);
Assert.Equal("file:///home/JamesHolden/projects/Rocinate/Proto%3AMole%5Ccule.ps1", scriptFile.DocumentUri);
}
}

[Trait("Category", "ScriptFile")]
[Theory]
[InlineData("C:\\Users\\me\\Documents\\test.ps1", false)]
[InlineData(@"C:\Users\me\Documents\test.ps1", false)]
[InlineData("/Users/me/Documents/test.ps1", false)]
[InlineData("vscode-notebook-cell:/Users/me/Documents/test.ps1#0001", true)]
[InlineData("https://microsoft.com", true)]
[InlineData("Untitled:Untitled-1", true)]
[InlineData("'a log statement' > 'c:\\Users\\me\\Documents\\test.txt'\r\n", false)]
[InlineData(@"'a log statement' > 'c:\Users\me\Documents\test.txt'
", false)]
public void IsUntitledFileIsCorrect(string path, bool expected) => Assert.Equal(expected, ScriptFile.IsUntitledPath(path));
}
}

0 comments on commit 9e19755

Please sign in to comment.