import { expect, test } from "vitest" import { isPathnameEqual, isPathnameLooseEqual, isPathnameStrictEqual, keepMinimumPathArray, neatenPathname, toPathnameArray, toPathnameString, removeInnerEmptyStringInArray, removeConsecutiveRepetition, removeConsecutiveRepetitionExcept, removeConsecutiveRepetitionOf, removeConsecutiveRepetitionOfEmpty, removeConsecutiveRepetitionOfSlash, } from "#Source/route/index.ts" test("removeConsecutiveRepetition removes adjacent duplicate items", () => { expect(removeConsecutiveRepetition(["", "", "app", "app", "page", "page", ""])).toEqual([ "", "app", "page", "", ]) expect(removeConsecutiveRepetition([])).toEqual([]) }) test("removeConsecutiveRepetitionOf removes adjacent duplicates only for selected values", () => { expect( removeConsecutiveRepetitionOf(["", "", "app", "/", "/", "page", "page"], ["", "/"]), ).toEqual(["", "app", "/", "page", "page"]) }) test("removeConsecutiveRepetitionExcept keeps repeated exceptions and removes others", () => { expect( removeConsecutiveRepetitionExcept(["", "", "app", "app", "page", "page", "", ""], [""]), ).toEqual(["", "", "app", "page", "", ""]) }) test("removeConsecutiveRepetitionOfEmpty removes only adjacent empty strings", () => { expect(removeConsecutiveRepetitionOfEmpty(["", "", "app", "", "", "page", ""])).toEqual([ "", "app", "", "page", "", ]) }) test("removeConsecutiveRepetitionOfSlash removes only adjacent slash characters", () => { expect(removeConsecutiveRepetitionOfSlash(["/", "/", "a", "/", "/", "/", "b"])).toEqual([ "/", "a", "/", "b", ]) }) test("removeInnerEmptyStringInArray keeps boundary empties and removes inner empties", () => { expect(removeInnerEmptyStringInArray(["", "app", "", "page", ""])).toEqual([ "", "app", "page", "", ]) expect(removeInnerEmptyStringInArray(["", "", "app", "", "page", "", ""])).toEqual([ "", "app", "page", "", ]) }) test("keepMinimumPathArray preserves the minimal root pathname representation", () => { expect(keepMinimumPathArray([""])).toEqual(["", ""]) expect(keepMinimumPathArray(["", "app"])).toEqual(["", "app"]) }) test("neatenPathname normalizes both array and string inputs", () => { expect(neatenPathname(["app", "", "page", ""])).toEqual(["", "app", "page", ""]) expect(neatenPathname("//app//page//")).toBe("/app/page/") }) test("toPathnameArray converts pathname inputs into normalized arrays", () => { const cases: Array<[string | string[], string[]]> = [ [[""], ["", ""]], [ ["", ""], ["", ""], ], [ ["app", "page"], ["", "app", "page"], ], [ ["", "app", "page"], ["", "app", "page"], ], [ ["", "app", "", "page"], ["", "app", "page"], ], [ ["", "app", "", "page", ""], ["", "app", "page", ""], ], [ ["", "", "app", "", "page", ""], ["", "app", "page", ""], ], [ ["", "", "app", "", "", "page", ""], ["", "app", "page", ""], ], [ ["", "", "app", "", "", "page", "", ""], ["", "app", "page", ""], ], ["", ["", ""]], ["/", ["", ""]], ["app/page", ["", "app", "page"]], ["/app/page", ["", "app", "page"]], ["/app/page/", ["", "app", "page", ""]], ["//app/page/", ["", "app", "page", ""]], ["//app//page/", ["", "app", "page", ""]], ["//app//page//", ["", "app", "page", ""]], ] cases.forEach(([input, expected]) => { expect(toPathnameArray(input)).toEqual(expected) }) }) test("toPathnameString converts pathname inputs into normalized strings", () => { const cases: Array<[string | string[], string]> = [ [[""], "/"], [["", ""], "/"], [["app", "page"], "/app/page"], [["", "app", "page"], "/app/page"], [["app", "", "page"], "/app/page"], [["app", "page", ""], "/app/page/"], [["", "app", "", "page", ""], "/app/page/"], [["", "", "app", "", "", "page", "", ""], "/app/page/"], ["", "/"], ["/", "/"], ["//", "/"], ["/app/page", "/app/page"], ["//app/page", "/app/page"], ["//app//page", "/app/page"], ["//app//page/", "/app/page/"], ["//app//page//", "/app/page/"], ] cases.forEach(([input, expected]) => { expect(toPathnameString(input)).toBe(expected) }) }) test("isPathnameStrictEqual compares normalized pathnames with trailing slash sensitivity", () => { const cases: Array<[string | string[], string | string[], boolean]> = [ ["", ["", ""], true], ["/", ["", ""], true], ["//app//page1//", ["", "app", "page1"], false], ["//app//page1//", ["", "app", "page1", ""], true], ] cases.forEach(([left, right, expected]) => { expect(isPathnameStrictEqual(left, right)).toBe(expected) }) }) test("isPathnameLooseEqual ignores trailing slash differences after normalization", () => { const cases: Array<[string | string[], string | string[], boolean]> = [ ["", ["", ""], true], ["/", ["", ""], true], ["//app//page1//", ["", "app", "page1"], true], ["//app//page1//", ["", "app", "page1", ""], true], ["/app/page", "/app/other/", false], ] cases.forEach(([left, right, expected]) => { expect(isPathnameLooseEqual(left, right)).toBe(expected) }) }) test("isPathnameEqual dispatches strict and loose modes and rejects invalid mode", () => { expect(isPathnameEqual("strict", "/app/page", ["", "app", "page"])).toBe(true) expect(isPathnameEqual("loose", "/app/page", "/app/page/")).toBe(true) expect(() => isPathnameEqual("other" as "strict", "/app/page", "/app/page")).toThrow( '"mode" must be "strict" or "loose".', ) })