diff --git a/src/lib/mark.test.ts b/src/lib/mark.test.ts index 2ec02f8..863789a 100644 --- a/src/lib/mark.test.ts +++ b/src/lib/mark.test.ts @@ -13,6 +13,10 @@ test("make mark, kill mark", () => { m = Marks.getMark(Marks.createMark(0)); expect(m?.location).toEqual(0); + let o = Marks.createMark(l, "gaming_corporate_office"); + expect(o).toEqual("gaming_corporate_office"); + + // delete when it exists and doesnt expect(Marks.removeMark(Marks.createMark())).toEqual(true); expect(Marks.removeMark("owo")).toEqual(true); }); diff --git a/src/lib/mark.ts b/src/lib/mark.ts index 9f3da75..aea7ad7 100644 --- a/src/lib/mark.ts +++ b/src/lib/mark.ts @@ -17,14 +17,14 @@ const makeMarkList = (): MarkList => { * @param location: where in the text to place the mark, positive int, optinal. * @return a mark, the marks location field is set to location if location passed is a positive int, -1 otherwise */ - const createMark = (location?: number): string => { + const createMark = (location?: number, name?: string): string => { const m = { location: location !== undefined && location >= 0 ? location : -1, fixed: false, }; - const name = (Math.random() + 1).toString(36).substring(2); - markTable.set(name, m); - return name; + const n = name || (Math.random() + 1).toString(36).substring(2); + markTable.set(n, m); + return n; }; /** remove a mark @@ -111,7 +111,7 @@ const makeMarkList = (): MarkList => { }; interface MarkList { - createMark: (location?: number) => string; + createMark: (location?: number, name?: string) => string; removeMark: (name: string) => boolean; getMark: (name: string) => Mark | undefined; whereIs: (name: string) => number | undefined;