|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | using Xunit; |
5 | | -using System.IO; |
6 | | -using Microsoft.PowerShell.EditorServices.Services; |
7 | 5 | using Microsoft.PowerShell.EditorServices.Utility; |
8 | 6 |
|
9 | 7 | namespace Microsoft.PowerShell.EditorServices.Test.Session |
10 | 8 | { |
11 | 9 | public class PathEscapingTests |
12 | 10 | { |
13 | | - private const string ScriptAssetPath = @"..\..\..\..\PowerShellEditorServices.Test.Shared\scriptassets"; |
14 | | - |
15 | 11 | [Trait("Category", "PathEscaping")] |
16 | 12 | [Theory] |
17 | 13 | [InlineData("DebugTest.ps1", "DebugTest.ps1")] |
@@ -53,68 +49,5 @@ public void CorrectlyWildcardEscapesPaths_Spaces(string unescapedPath, string es |
53 | 49 | string extensionEscapedPath = PathUtils.WildcardEscapePath(unescapedPath, escapeSpaces: true); |
54 | 50 | Assert.Equal(escapedPath, extensionEscapedPath); |
55 | 51 | } |
56 | | - |
57 | | - [Trait("Category", "PathEscaping")] |
58 | | - [Theory] |
59 | | - [InlineData("DebugTest.ps1", "'DebugTest.ps1'")] |
60 | | - [InlineData("../../DebugTest.ps1", "'../../DebugTest.ps1'")] |
61 | | - [InlineData("C:\\Users\\me\\Documents\\DebugTest.ps1", "'C:\\Users\\me\\Documents\\DebugTest.ps1'")] |
62 | | - [InlineData("/home/me/Documents/weird&folder/script.ps1", "'/home/me/Documents/weird&folder/script.ps1'")] |
63 | | - [InlineData("./path/with some/spaces", "'./path/with some/spaces'")] |
64 | | - [InlineData("C:\\path\\with[some]brackets\\file.ps1", "'C:\\path\\with[some]brackets\\file.ps1'")] |
65 | | - [InlineData("C:\\look\\an*\\here.ps1", "'C:\\look\\an*\\here.ps1'")] |
66 | | - [InlineData("/Users/me/Documents/?here.ps1", "'/Users/me/Documents/?here.ps1'")] |
67 | | - [InlineData("/Brackets [and s]paces/path.ps1", "'/Brackets [and s]paces/path.ps1'")] |
68 | | - [InlineData("/file path/that isn't/normal/", "'/file path/that isn''t/normal/'")] |
69 | | - [InlineData("/CJK.chars/脚本/hello.ps1", "'/CJK.chars/脚本/hello.ps1'")] |
70 | | - [InlineData("/CJK chars/脚本/[hello].ps1", "'/CJK chars/脚本/[hello].ps1'")] |
71 | | - [InlineData("C:\\Animal s\\утка\\quack.ps1", "'C:\\Animal s\\утка\\quack.ps1'")] |
72 | | - [InlineData("C:\\&nimals\\утка\\qu*ck?.ps1", "'C:\\&nimals\\утка\\qu*ck?.ps1'")] |
73 | | - public void CorrectlyQuoteEscapesPaths(string unquotedPath, string expectedQuotedPath) |
74 | | - { |
75 | | - string extensionQuotedPath = StringEscaping.SingleQuoteAndEscape(unquotedPath).ToString(); |
76 | | - Assert.Equal(expectedQuotedPath, extensionQuotedPath); |
77 | | - } |
78 | | - |
79 | | - [Trait("Category", "PathEscaping")] |
80 | | - [Theory] |
81 | | - [InlineData("DebugTest.ps1", "'DebugTest.ps1'")] |
82 | | - [InlineData("../../DebugTest.ps1", "'../../DebugTest.ps1'")] |
83 | | - [InlineData("C:\\Users\\me\\Documents\\DebugTest.ps1", "'C:\\Users\\me\\Documents\\DebugTest.ps1'")] |
84 | | - [InlineData("/home/me/Documents/weird&folder/script.ps1", "'/home/me/Documents/weird&folder/script.ps1'")] |
85 | | - [InlineData("./path/with some/spaces", "'./path/with some/spaces'")] |
86 | | - [InlineData("C:\\path\\with[some]brackets\\file.ps1", "'C:\\path\\with`[some`]brackets\\file.ps1'")] |
87 | | - [InlineData("C:\\look\\an*\\here.ps1", "'C:\\look\\an`*\\here.ps1'")] |
88 | | - [InlineData("/Users/me/Documents/?here.ps1", "'/Users/me/Documents/`?here.ps1'")] |
89 | | - [InlineData("/Brackets [and s]paces/path.ps1", "'/Brackets `[and s`]paces/path.ps1'")] |
90 | | - [InlineData("/file path/that isn't/normal/", "'/file path/that isn''t/normal/'")] |
91 | | - [InlineData("/CJK.chars/脚本/hello.ps1", "'/CJK.chars/脚本/hello.ps1'")] |
92 | | - [InlineData("/CJK chars/脚本/[hello].ps1", "'/CJK chars/脚本/`[hello`].ps1'")] |
93 | | - [InlineData("C:\\Animal s\\утка\\quack.ps1", "'C:\\Animal s\\утка\\quack.ps1'")] |
94 | | - [InlineData("C:\\&nimals\\утка\\qu*ck?.ps1", "'C:\\&nimals\\утка\\qu`*ck`?.ps1'")] |
95 | | - public void CorrectlyFullyEscapesPaths(string unescapedPath, string escapedPath) |
96 | | - { |
97 | | - string extensionEscapedPath = StringEscaping.SingleQuoteAndEscape(PathUtils.WildcardEscapePath(unescapedPath)).ToString(); |
98 | | - Assert.Equal(escapedPath, extensionEscapedPath); |
99 | | - } |
100 | | - |
101 | | - [Trait("Category", "PathEscaping")] |
102 | | - [Theory] |
103 | | - [InlineData("NormalScript.ps1")] |
104 | | - [InlineData("Bad&name4script.ps1")] |
105 | | - [InlineData("[Truly] b&d Name_4_script.ps1")] |
106 | | - public void CanDotSourcePath(string rawFileName) |
107 | | - { |
108 | | - string fullPath = Path.Combine(ScriptAssetPath, rawFileName); |
109 | | - string quotedPath = StringEscaping.SingleQuoteAndEscape(fullPath).ToString(); |
110 | | - |
111 | | - var psCommand = new System.Management.Automation.PSCommand().AddScript($". {quotedPath}"); |
112 | | - |
113 | | - using (var pwsh = System.Management.Automation.PowerShell.Create()) |
114 | | - { |
115 | | - pwsh.Commands = psCommand; |
116 | | - pwsh.Invoke(); |
117 | | - } |
118 | | - } |
119 | 52 | } |
120 | 53 | } |
0 commit comments