|
1 | 1 | using System; |
2 | 2 | using System.IO; |
3 | 3 | using System.Runtime.InteropServices; |
| 4 | +using AnakinRaW.CommonUtilities.Testing.Attributes; |
4 | 5 | using PG.StarWarsGame.Engine.Utilities; |
5 | 6 | using Xunit; |
6 | 7 |
|
@@ -150,6 +151,58 @@ public void FileExists_GameDirectory_WithTrailingSeparator() |
150 | 151 | } |
151 | 152 | } |
152 | 153 |
|
| 154 | + [PlatformSpecificFact(TestPlatformIdentifier.Linux)] |
| 155 | + public void FileExists_CaseInsensitive_DotSegmentInPath_ReturnsTrue() |
| 156 | + { |
| 157 | + var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); |
| 158 | + Directory.CreateDirectory(tempDir); |
| 159 | + |
| 160 | + try |
| 161 | + { |
| 162 | + // Create the actual file at tempDir/DATA/FILE.TXT (uppercase) |
| 163 | + Directory.CreateDirectory(Path.Combine(tempDir, "DATA")); |
| 164 | + File.WriteAllText(Path.Combine(tempDir, "DATA", "FILE.TXT"), "test"); |
| 165 | + |
| 166 | + // Input path uses a leading ".\" (dot-segment) AND different casing. |
| 167 | + // After normalization + join: tempDir/./DATA/file.txt |
| 168 | + // File.Exists fast-path fails (case mismatch), so the impl must resolve case-insensitively. |
| 169 | + // Correct impls must handle "." as a valid path segment that resolves to the current directory, |
| 170 | + // not treat it as a literal directory name to look up via GetDirectories. |
| 171 | + var vsb = new ValueStringBuilder(); |
| 172 | + var exists = _pgFileSystem.FileExists(@".\DATA\file.txt".AsSpan(), ref vsb, tempDir.AsSpan()); |
| 173 | + |
| 174 | + Assert.True(exists); |
| 175 | + } |
| 176 | + finally |
| 177 | + { |
| 178 | + Directory.Delete(tempDir, true); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + [PlatformSpecificFact(TestPlatformIdentifier.Linux)] |
| 183 | + public void FileExists_CaseInsensitive_MissingIntermediateDirectory_ReturnsFalse() |
| 184 | + { |
| 185 | + var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); |
| 186 | + Directory.CreateDirectory(tempDir); |
| 187 | + |
| 188 | + try |
| 189 | + { |
| 190 | + // Create tempDir/a/c.txt — no "b" directory at all |
| 191 | + Directory.CreateDirectory(Path.Combine(tempDir, "a")); |
| 192 | + File.WriteAllText(Path.Combine(tempDir, "a", "c.txt"), "test"); |
| 193 | + |
| 194 | + // Input path references a non-existent intermediate segment "b" |
| 195 | + var vsb = new ValueStringBuilder(); |
| 196 | + var exists = _pgFileSystem.FileExists("a/b/c.txt".AsSpan(), ref vsb, tempDir.AsSpan()); |
| 197 | + |
| 198 | + Assert.False(exists); |
| 199 | + } |
| 200 | + finally |
| 201 | + { |
| 202 | + Directory.Delete(tempDir, true); |
| 203 | + } |
| 204 | + } |
| 205 | + |
153 | 206 | [Theory] |
154 | 207 | #if Windows |
155 | 208 | [InlineData("C:\\test.txt", true)] |
|
0 commit comments