| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { hasWideMarkdownBlock } from "./wideMarkdownBlocks"; |
| 4 | |
| 5 | describe("hasWideMarkdownBlock", () => { |
| 6 | it("ignores prose, inline code, and emphasis", () => { |
| 7 | expect(hasWideMarkdownBlock("just a message")).toBe(false); |
| 8 | expect(hasWideMarkdownBlock("I found it in `secteurs_intervention` earlier")).toBe(false); |
| 9 | expect(hasWideMarkdownBlock("a | b in a sentence")).toBe(false); |
| 10 | expect(hasWideMarkdownBlock("an em dash — and a rule\n\n---\n")).toBe(false); |
| 11 | }); |
| 12 | |
| 13 | it("detects fenced code blocks", () => { |
| 14 | expect(hasWideMarkdownBlock("before\n```\ncode\n```\nafter")).toBe(true); |
| 15 | expect(hasWideMarkdownBlock("before\n```ts\ncode\n```")).toBe(true); |
| 16 | expect(hasWideMarkdownBlock("before\n~~~\ncode\n~~~")).toBe(true); |
| 17 | expect(hasWideMarkdownBlock(" ```\ncode\n```")).toBe(true); |
| 18 | }); |
| 19 | |
| 20 | it("detects indented code blocks", () => { |
| 21 | const prompt = 'before\n\n def search(x):\n return x\n\n"""\n\nafter'; |
| 22 | expect(hasWideMarkdownBlock(prompt)).toBe(true); |
| 23 | expect(hasWideMarkdownBlock("before\n\n\treturn x\n\nafter")).toBe(true); |
| 24 | expect(hasWideMarkdownBlock("before\n\n \treturn x\n\nafter")).toBe(true); |
| 25 | expect(hasWideMarkdownBlock("> return x")).toBe(true); |
| 26 | expect(hasWideMarkdownBlock("> > \treturn x")).toBe(true); |
| 27 | expect(hasWideMarkdownBlock(" 1. indented code")).toBe(true); |
| 28 | expect(hasWideMarkdownBlock(" - code-like bullet")).toBe(true); |
| 29 | expect(hasWideMarkdownBlock("before\n not code\nafter")).toBe(false); |
| 30 | expect(hasWideMarkdownBlock("before\n \nafter")).toBe(false); |
| 31 | expect(hasWideMarkdownBlock("before\n \t\nafter")).toBe(false); |
| 32 | }); |
| 33 | |
| 34 | it("detects top-level and blockquoted ordered-list markers", () => { |
| 35 | expect(hasWideMarkdownBlock("1. One\n2. Two\n3. Three\n4. Four\n5. Five")).toBe(true); |
| 36 | expect(hasWideMarkdownBlock("before\n3) Three")).toBe(true); |
| 37 | expect(hasWideMarkdownBlock("> 1. One\n> 2. Two")).toBe(true); |
| 38 | expect(hasWideMarkdownBlock("> > 3) Three")).toBe(true); |
| 39 | }); |
| 40 | |
| 41 | it("detects nested ordered lists", () => { |
| 42 | expect(hasWideMarkdownBlock("- Parent\n 1. Child\n 2. Child")).toBe(true); |
| 43 | expect(hasWideMarkdownBlock("> - Parent\n> 1. Child")).toBe(true); |
| 44 | }); |
| 45 | |
| 46 | it("can limit ordered-list width pinning to Android", () => { |
| 47 | const orderedList = "1. One\n2. Two"; |
| 48 | expect(hasWideMarkdownBlock(orderedList, { includeOrderedLists: true })).toBe(true); |
| 49 | expect(hasWideMarkdownBlock(orderedList, { includeOrderedLists: false })).toBe(false); |
| 50 | expect(hasWideMarkdownBlock("```\ncode\n```", { includeOrderedLists: false })).toBe(true); |
| 51 | expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |", { includeOrderedLists: false })).toBe( |
| 52 | true, |
| 53 | ); |
| 54 | }); |
| 55 | |
| 56 | it("detects blockquotes only when the native renderer needs width pinning", () => { |
| 57 | expect(hasWideMarkdownBlock("> quoted", { includeBlockquotes: true })).toBe(true); |
| 58 | expect(hasWideMarkdownBlock(" > quoted", { includeBlockquotes: true })).toBe(true); |
| 59 | expect(hasWideMarkdownBlock("> quoted")).toBe(false); |
| 60 | expect(hasWideMarkdownBlock("prose > quoted", { includeBlockquotes: true })).toBe(false); |
| 61 | expect(hasWideMarkdownBlock(" > indented code", { includeBlockquotes: true })).toBe(true); |
| 62 | }); |
| 63 | |
| 64 | it("detects GFM tables", () => { |
| 65 | expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |\n| 1 | 2 |")).toBe(true); |
| 66 | expect(hasWideMarkdownBlock("a | b\n:-- | --:\n1 | 2")).toBe(true); |
| 67 | }); |
| 68 | }); |