Skip to content

Commit

Permalink
#1806 nullable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 9, 2024
1 parent 6d41f36 commit fcdce79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ describe("CommaSeperatedFileList", () => {
expect(result).toBe("__test123__");
});

test("should ignore/handle empty string translated for inputs without dots", () => {
// yes empty string is a non-valid option
const result = comma.CommaSpaceLastDot(["example.test", "another", "final.test"], "");
expect(result).toBe(", test");
});

test("should ignore/handle null translated for inputs without dots", () => {
// yes null is a non-valid option
const result = comma.CommaSpaceLastDot(["example.test", "another", "final.test"], null!);
expect(result).toBe("test, without extension");
});

test("should handle mixed inputs with and without dots", () => {
const result = comma.CommaSpaceLastDot(["example.test", "another", "final.test"]);
expect(result).toBe("test, without extension");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export class CommaSeperatedFileList {

private GetUniqueExtensions(inputs: string[], messageNoExtensionItem?: string): Array<string> {
const uniqueExtensions = new Set<string>();
const messageNoExtension = messageNoExtensionItem ?? "without extension";

for (const element of inputs) {
const fileExtension = element.split(".")[element.split(".").length - 1];
if (element !== fileExtension) {
uniqueExtensions.add(fileExtension);
} else {
uniqueExtensions.add(messageNoExtensionItem || "without extension");
uniqueExtensions.add(messageNoExtension);
}
}
return Array.from(uniqueExtensions).sort((a, b) =>
Expand Down

0 comments on commit fcdce79

Please sign in to comment.