Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ImageDescriber.Test/ImageScannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,30 @@
Directory.Delete(tempDir, true);
}
}

[TestMethod]
public void ScanForImagesMatchesExtensionsCaseInsensitively()
{
string tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempDir);

try
{
File.WriteAllBytes(Path.Combine(tempDir, "IMG_0001.JPG"), [0xFF, 0xD8]);
File.WriteAllBytes(Path.Combine(tempDir, "screenshot.Png"), [0x89, 0x50]);
File.WriteAllBytes(Path.Combine(tempDir, "photo.jpeg"), [0xFF, 0xD8]);
File.WriteAllBytes(Path.Combine(tempDir, "scan.TIFF"), [0x49, 0x49]);
File.WriteAllText(Path.Combine(tempDir, "NOTES.TXT"), "text");

IReadOnlyList<AbsoluteFilePath> results = ImageScanner.ScanForImages(tempDir.As<AbsoluteDirectoryPath>());

string[] names = [.. results.Select(r => Path.GetFileName(r.WeakString)).Order(StringComparer.Ordinal)];
string[] expected = ["IMG_0001.JPG", "photo.jpeg", "scan.TIFF", "screenshot.Png"];
CollectionAssert.AreEqual(expected, names);

Check warning on line 148 in ImageDescriber.Test/ImageScannerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.AreSequenceEqual' instead of 'CollectionAssert.AreEqual'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_ImageDescriber&issues=AaDcnTQRy29mLvhC3i9l&open=AaDcnTQRy29mLvhC3i9l&pullRequest=152
}
finally
{
Directory.Delete(tempDir, true);
}
}
}
4 changes: 3 additions & 1 deletion ImageDescriber/ImageScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ internal static IReadOnlyList<AbsoluteFilePath> ScanForImages(AbsoluteDirectoryP
continue;
}

if (ImageExtensions.Contains(ext.As<FileExtension>()))
// FileExtension compares ordinally, and cameras and Windows tools write .JPG/.PNG,
// so fold to the lower-case form the set holds before looking it up.
if (ImageExtensions.Contains(ext.ToLowerInvariant().As<FileExtension>()))
{
imageFiles.Add(file.As<AbsoluteFilePath>());
}
Expand Down
Loading