highlightMatches.test.ts 797 B

1234567891011121314151617181920212223
  1. import { describe, expect, it } from "vitest";
  2. import { findTextMatchRanges } from "@/quickpick/HighlightedMatchText.js";
  3. describe("findTextMatchRanges", () => {
  4. it("matches case-insensitive query parts", () => {
  5. expect(findTextMatchRanges("src/App.tsx", "SRC tsx")).toEqual([
  6. { start: 0, end: 3 },
  7. { start: 8, end: 11 },
  8. ]);
  9. });
  10. it("merges overlapping ranges from multiple query parts", () => {
  11. expect(findTextMatchRanges("foobar", "foo foob")).toEqual([{ start: 0, end: 4 }]);
  12. });
  13. it("ignores empty and duplicate query parts", () => {
  14. expect(findTextMatchRanges("banana", " an an ")).toEqual([{ start: 1, end: 5 }]);
  15. });
  16. it("returns no ranges when query is blank", () => {
  17. expect(findTextMatchRanges("App.tsx", " ")).toEqual([]);
  18. });
  19. });