























@@ -23,7 +23,10 @@ describe("wave-11 malformed-input", () => {
2323});
24242525it("M-03 only `---` (single fence, no content)", () => {
26-expect(() => parseMd("---\n")).not.toThrow();
26+const { ast, diagnostics } = parseMd("---\n");
27+expect(diagnostics.map((diagnostic) => diagnostic.code)).toContain("OC_FRONTMATTER_UNCLOSED");
28+expect(ast.frontmatter).toEqual([]);
29+expect(ast.preamble).toBe("---\n");
2730});
28312932it("M-04 only `---\\n---`", () => {
@@ -33,7 +36,9 @@ describe("wave-11 malformed-input", () => {
33363437it("M-05 binary-ish bytes (non-ASCII control chars)", () => {
3538const raw = "## H\n\x00\x01\x02\n";
36-expect(() => parseMd(raw)).not.toThrow();
39+const { ast, diagnostics } = parseMd(raw);
40+expect(diagnostics).toEqual([]);
41+expect(ast.blocks[0]?.bodyText).toBe("\x00\x01\x02\n");
3742});
38433944it("M-06 very long single line (10k chars)", () => {
@@ -60,17 +65,20 @@ describe("wave-11 malformed-input", () => {
60656166it("M-09 unclosed code fence", () => {
6267const raw = "## H\n```\nbody\n";
63-expect(() => parseMd(raw)).not.toThrow();
68+const { ast } = parseMd(raw);
69+expect(ast.blocks[0]?.bodyText).toBe("```\nbody\n");
6470});
65716672it("M-10 mismatched fence (open with ``` close with ~~~)", () => {
6773const raw = "## H\n```\nbody\n~~~\n";
68-expect(() => parseMd(raw)).not.toThrow();
74+const { ast } = parseMd(raw);
75+expect(ast.blocks[0]?.bodyText).toBe("```\nbody\n~~~\n");
6976});
70777178it("M-11 nested fences (treated linearly, not nested)", () => {
7279const raw = "## H\n```\n```\nstill-in-second\n```\n";
73-expect(() => parseMd(raw)).not.toThrow();
80+const { ast } = parseMd(raw);
81+expect(ast.blocks[0]?.bodyText).toBe("```\n```\nstill-in-second\n```\n");
7482});
75837684it("M-12 empty file", () => {
@@ -94,7 +102,8 @@ describe("wave-11 malformed-input", () => {
9410295103it("M-15 file with mixed indentation extremes (tabs, spaces, mixed)", () => {
96104const raw = "## H\n\t- tabbed\n - spaced\n\t - mixed\n";
97-expect(() => parseMd(raw)).not.toThrow();
105+const { ast } = parseMd(raw);
106+expect(ast.blocks[0]?.bodyText).toBe("\t- tabbed\n - spaced\n\t - mixed\n");
98107});
99108100109it("M-16 frontmatter with frontmatter-shaped content inside (---)", () => {
@@ -119,7 +128,10 @@ describe("wave-11 malformed-input", () => {
119128});
120129121130it("M-19 file with just whitespace", () => {
122-expect(() => parseMd(" \n\t\n \n")).not.toThrow();
131+const { ast, diagnostics } = parseMd(" \n\t\n \n");
132+expect(diagnostics).toEqual([]);
133+expect(ast.preamble).toBe(" \n\t\n \n");
134+expect(ast.blocks).toEqual([]);
123135});
124136125137it("M-20 file with only BOM", () => {
@@ -129,16 +141,18 @@ describe("wave-11 malformed-input", () => {
129141130142it("M-21 file mixing BOM + frontmatter + body + sections", () => {
131143const raw = "---\nk: v\n---\n\nbody\n## Section\n- item\n";
132-expect(() => parseMd(raw)).not.toThrow();
133144const { ast } = parseMd(raw);
134145expect(ast.frontmatter[0]?.value).toBe("v");
135146expect(ast.blocks[0]?.heading).toBe("Section");
147+expect(ast.blocks[0]?.items[0]?.text).toBe("item");
136148});
137149138150it("M-22 line endings: legacy CR-only (Mac classic)", () => {
139151// Our regex /\r?\n/ doesn't split on CR-only. Treats whole as one line.
140152const raw = "line1\rline2\r## Heading\r";
141-expect(() => parseMd(raw)).not.toThrow();
153+const { ast } = parseMd(raw);
154+expect(ast.preamble).toBe(raw);
155+expect(ast.blocks).toEqual([]);
142156});
143157144158it("M-23 100 KB file", () => {
@@ -150,6 +164,9 @@ describe("wave-11 malformed-input", () => {
150164}
151165}
152166const raw = lines.join("\n");
153-expect(() => parseMd(raw)).not.toThrow();
167+const { ast, diagnostics } = parseMd(raw);
168+expect(diagnostics).toEqual([]);
169+expect(ast.blocks).toHaveLength(1000);
170+expect(ast.blocks[999]?.items).toHaveLength(5);
154171});
155172});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。