48 lines · 2.3 KB · TypeScript
RawDownload
import { describe, expect, it } from "vite-plus/test"; import { hasWideMarkdownBlock } from "./wideMarkdownBlocks"; describe("hasWideMarkdownBlock", () => {  it("ignores prose, inline code, and emphasis", () => {    expect(hasWideMarkdownBlock("just a message")).toBe(false);    expect(hasWideMarkdownBlock("I found it in `secteurs_intervention` earlier")).toBe(false);    expect(hasWideMarkdownBlock("a | b in a sentence")).toBe(false);    expect(hasWideMarkdownBlock("an em dash — and a rule\n\n---\n")).toBe(false);  });   it("detects fenced code blocks", () => {    expect(hasWideMarkdownBlock("before\n```\ncode\n```\nafter")).toBe(true);    expect(hasWideMarkdownBlock("before\n```ts\ncode\n```")).toBe(true);    expect(hasWideMarkdownBlock("before\n~~~\ncode\n~~~")).toBe(true);    expect(hasWideMarkdownBlock("   ```\ncode\n```")).toBe(true);  });   it("detects top-level and blockquoted ordered-list markers", () => {    expect(hasWideMarkdownBlock("1. One\n2. Two\n3. Three\n4. Four\n5. Five")).toBe(true);    expect(hasWideMarkdownBlock("before\n3) Three")).toBe(true);    expect(hasWideMarkdownBlock("> 1. One\n> 2. Two")).toBe(true);    expect(hasWideMarkdownBlock("> > 3) Three")).toBe(true);  });   it("detects nested ordered lists without treating indented code as a list", () => {    expect(hasWideMarkdownBlock("- Parent\n    1. Child\n    2. Child")).toBe(true);    expect(hasWideMarkdownBlock("> - Parent\n>     1. Child")).toBe(true);    expect(hasWideMarkdownBlock("    1. indented code")).toBe(false);    expect(hasWideMarkdownBlock("    - code-like bullet\n    1. indented code")).toBe(false);  });   it("can limit ordered-list width pinning to Android", () => {    const orderedList = "1. One\n2. Two";    expect(hasWideMarkdownBlock(orderedList, { includeOrderedLists: true })).toBe(true);    expect(hasWideMarkdownBlock(orderedList, { includeOrderedLists: false })).toBe(false);    expect(hasWideMarkdownBlock("```\ncode\n```", { includeOrderedLists: false })).toBe(true);    expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |", { includeOrderedLists: false })).toBe(      true,    );  });   it("detects GFM tables", () => {    expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |\n| 1 | 2 |")).toBe(true);    expect(hasWideMarkdownBlock("a | b\n:-- | --:\n1 | 2")).toBe(true);  });});