Repository navigation
Expand file tree
/
Copy pathProgramRunnerTests.Wizard.cs
More file actions
159 lines (142 loc) · 8.3 KB
/
Copy pathProgramRunnerTests.Wizard.cs
File metadata and controls
159 lines (142 loc) · 8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// ProgramRunnerTests.Wizard.cs — NormalizeDragDropPath tests (partial)
// ProgramRunnerTests.Wizard.cs — NormalizeDragDropPath テスト(パーシャル)
using System;
using Xunit;
namespace FolderDiffIL4DotNet.Tests
{
public sealed partial class ProgramRunnerTests
{
// ── NormalizeDragDropPath tests ───────────────────────────────────
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_PlainPath_PassesThrough()
{
// A simple path without quotes or special prefixes should pass through unchanged.
// クォートや特殊プレフィックスのない単純なパスはそのまま通過すべき。
Assert.Equal("/home/user/folder", ProgramRunner.NormalizeDragDropPath("/home/user/folder"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_DoubleQuotedPath_StripsQuotes()
{
// Paths wrapped in double quotes (common Windows D&D) should have quotes removed.
// ダブルクォートで囲まれたパス(Windows D&D で一般的)はクォートが除去されるべき。
Assert.Equal(@"C:\Users\test\folder", ProgramRunner.NormalizeDragDropPath(@"""C:\Users\test\folder"""));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_SingleQuotedPath_StripsQuotes()
{
// Paths wrapped in single quotes (common macOS/Linux terminal D&D) should have quotes removed.
// シングルクォートで囲まれたパス(macOS/Linux ターミナル D&D で一般的)はクォートが除去されるべき。
Assert.Equal("/home/user/my folder", ProgramRunner.NormalizeDragDropPath("'/home/user/my folder'"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_FileUriTripleSlash_StripsPrefix()
{
// file:/// URI prefix (some Linux file managers) should be stripped.
// file:/// URI プレフィックス(一部の Linux ファイルマネージャ)は除去されるべき。
Assert.Equal("/home/user/folder", ProgramRunner.NormalizeDragDropPath("file:///home/user/folder"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_FileUriDoubleSlash_StripsPrefix()
{
// file:// URI with an authority component should be preserved as a UNC-style path.
// authority を持つ file:// URI は UNC 風パスとして保持されるべき。
Assert.Equal("//server/share", ProgramRunner.NormalizeDragDropPath("file://server/share"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_FileUriLocalhost_UsesLocalPath()
{
// file://localhost should normalize to the local absolute path, not a UNC-style path.
// file://localhost は UNC 風ではなくローカル絶対パスへ正規化されるべき。
Assert.Equal("/home/user/folder", ProgramRunner.NormalizeDragDropPath("file://localhost/home/user/folder"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_BackslashEscapedSpaces_Unescaped()
{
// Backslash-escaped spaces (Unix terminal D&D without quotes) should be unescaped.
// バックスラッシュでエスケープされたスペース(Unix ターミナルのクォートなし D&D)はアンエスケープされるべき。
Assert.Equal("/home/user/my folder/sub dir", ProgramRunner.NormalizeDragDropPath(@"/home/user/my\ folder/sub\ dir"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_PercentEncodedSpaces_Decoded()
{
// URI percent-encoded paths should be decoded.
// URI パーセントエンコードされたパスはデコードされるべき。
Assert.Equal("/home/user/my folder", ProgramRunner.NormalizeDragDropPath("/home/user/my%20folder"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_PercentEncodedJapanese_Decoded()
{
// Percent-encoded Japanese characters should be decoded.
// パーセントエンコードされた日本語文字はデコードされるべき。
string encoded = Uri.EscapeDataString("テスト");
Assert.Equal("/home/テスト", ProgramRunner.NormalizeDragDropPath($"/home/{encoded}"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_SurroundingWhitespace_Trimmed()
{
// Leading and trailing whitespace should be trimmed.
// 先頭と末尾の空白はトリムされるべき。
Assert.Equal("/home/user/folder", ProgramRunner.NormalizeDragDropPath(" /home/user/folder "));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_CombinedQuotesAndUri_HandledCorrectly()
{
// Combination of quotes and file:// URI should both be handled.
// クォートと file:// URI の組み合わせも両方処理されるべき。
Assert.Equal("/home/user/folder", ProgramRunner.NormalizeDragDropPath("'file:///home/user/folder'"));
}
[Fact]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_EmptyInput_ReturnsEmpty()
{
// Empty input should return empty string.
// 空入力は空文字列を返すべき。
Assert.Equal("", ProgramRunner.NormalizeDragDropPath(""));
Assert.Equal("", ProgramRunner.NormalizeDragDropPath(" "));
}
[Theory]
[Trait("Category", "Unit")]
// On current .NET 8+ runtimes `Uri.UnescapeDataString` returns malformed %-encoding unchanged
// instead of throwing. The catch is narrowed to only `UriFormatException`/`ArgumentException`,
// so the prior contract "crash-free, malformed segment preserved" must hold for each input
// regardless of which branch (no-op or caught-exception fallback) the runtime takes.
// 現在の .NET 8 以降では `Uri.UnescapeDataString` は不正な %-encoding を投げずにそのまま返す。
// catch は `UriFormatException`/`ArgumentException` のみに絞っているため、ランタイムが
// no-op 分岐でも catch 分岐でも、「crash しない/不正セグメントを保持する」という契約は
// どの入力でも維持される必要がある。
[InlineData("/home/user/file%ZZname")]
[InlineData("/home/user/file%G0name")]
[InlineData("/home/user/file%trailing")]
[InlineData("/home/user/%E3%81%AAname")] // valid UTF-8 percent encoding (hiragana "な") — must decode / 妥当な UTF-8 パーセントエンコード(ひらがな "な")— デコードされる
public void NormalizeDragDropPath_MalformedPercentEncoding_DoesNotThrowAndPreservesIdentifiablePathSegment(string input)
{
string result = ProgramRunner.NormalizeDragDropPath(input);
Assert.False(string.IsNullOrEmpty(result));
// Pin: the leading directory portion must not be stripped/truncated for any of these inputs.
// pin: 先頭ディレクトリ部分は、いずれの入力でも切り落とされてはいけない。
Assert.Contains("/home/user/", result, System.StringComparison.Ordinal);
}
[Theory]
[InlineData(@"""C:\folder with spaces\subfolder""", @"C:\folder with spaces\subfolder")]
[InlineData("'/Users/test/My Documents'", "/Users/test/My Documents")]
[InlineData("file:///home/user/test/folder", "/home/user/test/folder")]
[Trait("Category", "Unit")]
public void NormalizeDragDropPath_VariousDragDropFormats_NormalizedCorrectly(string input, string expected)
{
// Various D&D formats should all normalize correctly.
// 各種 D&D フォーマットがすべて正しく正規化されるべき。
Assert.Equal(expected, ProgramRunner.NormalizeDragDropPath(input));
}
}
}