|
1 | | -import { getContentAsString, isWhitedOutFile } from "../../../lib/extractor"; |
| 1 | +import { getContentAsString, isWhitedOutFile, removeWhiteoutPrefix } from "../../../lib/extractor"; |
2 | 2 | import { ExtractAction, ExtractedLayers } from "../../../lib/extractor/types"; |
3 | 3 |
|
4 | 4 | describe("index", () => { |
@@ -55,3 +55,44 @@ describe("isWhitedOutFile", () => { |
55 | 55 | expect(isWhitedOutFile("/the/.wh./in/path/present")).toBe(false); |
56 | 56 | }); |
57 | 57 | }); |
| 58 | + |
| 59 | +describe("removeWhiteoutPrefix", () => { |
| 60 | + test("should remove .wh. prefix from filenames without slashes", () => { |
| 61 | + expect(removeWhiteoutPrefix(".wh.hosts")).toBe("hosts"); |
| 62 | + expect(removeWhiteoutPrefix(".wh.data")).toBe("data"); |
| 63 | + expect(removeWhiteoutPrefix(".wh.config")).toBe("config"); |
| 64 | + expect(removeWhiteoutPrefix(".wh.")).toBe(""); |
| 65 | + expect(removeWhiteoutPrefix(".wh.file.txt")).toBe("file.txt"); |
| 66 | + }); |
| 67 | + |
| 68 | + test("should remove .wh. prefix after the last slash in paths", () => { |
| 69 | + expect(removeWhiteoutPrefix("/etc/.wh.hosts")).toBe("/etc/hosts"); |
| 70 | + expect(removeWhiteoutPrefix("/var/lib/.wh.data")).toBe("/var/lib/data"); |
| 71 | + expect(removeWhiteoutPrefix("/.wh.config")).toBe("/config"); |
| 72 | + expect(removeWhiteoutPrefix("/deeply/nested/path/.wh.present")).toBe("/deeply/nested/path/present"); |
| 73 | + expect(removeWhiteoutPrefix("/path/to/.wh.")).toBe("/path/to/"); |
| 74 | + }); |
| 75 | + |
| 76 | + test("should not modify files that don't have .wh. prefix in the correct position", () => { |
| 77 | + expect(removeWhiteoutPrefix("normal.file")).toBe("normal.file"); |
| 78 | + expect(removeWhiteoutPrefix("/etc/hosts")).toBe("/etc/hosts"); |
| 79 | + expect(removeWhiteoutPrefix("middle.wh.file")).toBe("middle.wh.file"); |
| 80 | + expect(removeWhiteoutPrefix("/path/middle.wh.file")).toBe("/path/middle.wh.file"); |
| 81 | + expect(removeWhiteoutPrefix(".whfile")).toBe(".whfile"); |
| 82 | + expect(removeWhiteoutPrefix("/path/.whfile")).toBe("/path/.whfile"); |
| 83 | + expect(removeWhiteoutPrefix("/path/has/.wh./in/middle")).toBe("/path/has/.wh./in/middle"); |
| 84 | + }); |
| 85 | + |
| 86 | + test("should handle edge cases", () => { |
| 87 | + expect(removeWhiteoutPrefix("")).toBe(""); |
| 88 | + expect(removeWhiteoutPrefix("/")).toBe("/"); |
| 89 | + expect(removeWhiteoutPrefix("//")).toBe("//"); |
| 90 | + expect(removeWhiteoutPrefix("/.wh.")).toBe("/"); |
| 91 | + expect(removeWhiteoutPrefix("//.wh.test")).toBe("//test"); |
| 92 | + }); |
| 93 | + |
| 94 | + test("should not remove .wh. that appears in the middle of paths", () => { |
| 95 | + expect(removeWhiteoutPrefix("/the/.wh./in/path/file")).toBe("/the/.wh./in/path/file"); |
| 96 | + expect(removeWhiteoutPrefix("/path/.wh.dir/.wh.file")).toBe("/path/.wh.dir/file"); |
| 97 | + }); |
| 98 | +}); |
0 commit comments