|
1 | 1 | import { wrappedIndentColumns } from "cm/indentedLineWrapping"; |
2 | | -import { describe, expect, it } from "vitest"; |
| 2 | +import { describe, expect, it, vi } from "vitest"; |
3 | 3 |
|
4 | 4 | describe("wrapped line indentation", () => { |
5 | 5 | it("preserves space indentation and stops at content", () => { |
@@ -37,4 +37,24 @@ describe("wrapped line indentation", () => { |
37 | 37 | expect(wrappedIndentColumns(" key\tvalue", 4, 7, "deepIndent")).toBe(4); |
38 | 38 | expect(wrappedIndentColumns(" code", 4, 7, "deepIndent")).toBe(7); |
39 | 39 | }); |
| 40 | + it("caps unindented lines at whole tab stops without depending on content tabs", () => { |
| 41 | + for (const text of ["code", "key\tvalue"]) { |
| 42 | + expect(wrappedIndentColumns(text, 4, 7, "deepIndent")).toBe(4); |
| 43 | + expect(wrappedIndentColumns(text, 4, 3, "indent")).toBe(0); |
| 44 | + } |
| 45 | + }); |
| 46 | + it("skips the full-line tab search for large unindented lines in extra-indent modes", () => { |
| 47 | + const text = "x".repeat(1_000_000) + "\tvalue"; |
| 48 | + const search = vi.spyOn(String.prototype, "includes"); |
| 49 | + let calls: number; |
| 50 | + try { |
| 51 | + wrappedIndentColumns(text, 4, 40, "indent"); |
| 52 | + wrappedIndentColumns(text, 4, 40, "deepIndent"); |
| 53 | + wrappedIndentColumns(text, 4, 7, "deepIndent"); |
| 54 | + calls = search.mock.calls.length; |
| 55 | + } finally { |
| 56 | + search.mockRestore(); |
| 57 | + } |
| 58 | + expect(calls).toBe(0); |
| 59 | + }); |
40 | 60 | }); |
0 commit comments