|
| 1 | +import { FilePathSet } from "../../../src/common/file-path-set"; |
| 2 | + |
| 3 | +describe("FilePathSet", () => { |
| 4 | + describe("isEmpty", () => { |
| 5 | + it("should return true only when set is empty", () => { |
| 6 | + const v = new FilePathSet(); |
| 7 | + expect(v.isEmpty()).toBe(true); |
| 8 | + |
| 9 | + v.addPath("/foo"); |
| 10 | + expect(v.isEmpty()).toBe(false); |
| 11 | + |
| 12 | + v.popPath(); |
| 13 | + expect(v.isEmpty()).toBe(true); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + describe("addPath / popPath", () => { |
| 18 | + it("should keep all paths when they don't overlap", () => { |
| 19 | + const v = new FilePathSet(); |
| 20 | + v.addPath("/foo"); |
| 21 | + v.addPath("/bar"); |
| 22 | + v.addPath("/baz"); |
| 23 | + expect(v.popPath()).toBe("/foo"); |
| 24 | + expect(v.popPath()).toBe("/bar"); |
| 25 | + expect(v.popPath()).toBe("/baz"); |
| 26 | + expect(v.popPath()).toBe(undefined); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should only keep one copy of repeated paths", () => { |
| 30 | + const v = new FilePathSet(); |
| 31 | + v.addPath("/foo"); |
| 32 | + v.addPath("/foo"); |
| 33 | + v.addPath("/foo"); |
| 34 | + expect(v.popPath()).toBe("/foo"); |
| 35 | + expect(v.popPath()).toBe(undefined); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should adding adding paths that are children of existing paths", () => { |
| 39 | + const v = new FilePathSet(); |
| 40 | + v.addPath("/foo"); |
| 41 | + v.addPath("/foo/bar"); |
| 42 | + v.addPath("/foo/baz"); |
| 43 | + expect(v.popPath()).toBe("/foo"); |
| 44 | + expect(v.popPath()).toBe(undefined); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should remove existing paths that are children of new paths", () => { |
| 48 | + const v = new FilePathSet(); |
| 49 | + v.addPath("/foo"); |
| 50 | + v.addPath("/bar/baz"); |
| 51 | + v.addPath("/bar/qux"); |
| 52 | + v.addPath("/bar"); |
| 53 | + expect(v.popPath()).toBe("/foo"); |
| 54 | + expect(v.popPath()).toBe("/bar"); |
| 55 | + expect(v.popPath()).toBe(undefined); |
| 56 | + }); |
| 57 | + }); |
| 58 | +}); |
0 commit comments