Skip to content

Commit 01370d9

Browse files
committed
Add Linux-specific tests for case-insensitive file existence handling in PetroglyphFileSystem
1 parent 7eb7357 commit 01370d9

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem.Test/IO/PetroglyphFileSystemTests.Exist.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Runtime.InteropServices;
4+
using AnakinRaW.CommonUtilities.Testing.Attributes;
45
using PG.StarWarsGame.Engine.Utilities;
56
using Xunit;
67

@@ -150,6 +151,58 @@ public void FileExists_GameDirectory_WithTrailingSeparator()
150151
}
151152
}
152153

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+
153206
[Theory]
154207
#if Windows
155208
[InlineData("C:\\test.txt", true)]

0 commit comments

Comments
 (0)