forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir.table-code.test.ts
More file actions
89 lines (73 loc) · 2.69 KB
/
Copy pathir.table-code.test.ts
File metadata and controls
89 lines (73 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { describe, expect, it } from "vitest";
import { markdownToIR } from "./ir.js";
describe("markdownToIR tableMode code - style overlap", () => {
it("should not have overlapping styles when cell has bold text", () => {
const md = `
| Name | Value |
|------|-------|
| **Bold** | Normal |
`.trim();
const ir = markdownToIR(md, { tableMode: "code" });
// Check for overlapping styles
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
const boldSpan = ir.styles.find((s) => s.style === "bold");
// Either:
// 1. There should be no bold spans in code mode (inner styles stripped), OR
// 2. If bold spans exist, they should not overlap with code_block span
if (codeBlockSpan && boldSpan) {
// Check for overlap
const overlaps = boldSpan.start < codeBlockSpan.end && boldSpan.end > codeBlockSpan.start;
// Overlapping styles are the bug - this should fail until fixed
expect(overlaps).toBe(false);
}
});
it("should not have overlapping styles when cell has italic text", () => {
const md = `
| Name | Value |
|------|-------|
| *Italic* | Normal |
`.trim();
const ir = markdownToIR(md, { tableMode: "code" });
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
const italicSpan = ir.styles.find((s) => s.style === "italic");
if (codeBlockSpan && italicSpan) {
const overlaps = italicSpan.start < codeBlockSpan.end && italicSpan.end > codeBlockSpan.start;
expect(overlaps).toBe(false);
}
});
it("should not have overlapping styles when cell has inline code", () => {
const md = `
| Name | Value |
|------|-------|
| \`code\` | Normal |
`.trim();
const ir = markdownToIR(md, { tableMode: "code" });
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
const codeSpan = ir.styles.find((s) => s.style === "code");
if (codeBlockSpan && codeSpan) {
const overlaps = codeSpan.start < codeBlockSpan.end && codeSpan.end > codeBlockSpan.start;
expect(overlaps).toBe(false);
}
});
it("should not have overlapping styles with multiple styled cells", () => {
const md = `
| Name | Value |
|------|-------|
| **A** | *B* |
| _C_ | ~~D~~ |
`.trim();
const ir = markdownToIR(md, { tableMode: "code" });
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
if (!codeBlockSpan) {
return;
}
// Check that no non-code_block style overlaps with code_block
for (const style of ir.styles) {
if (style.style === "code_block") {
continue;
}
const overlaps = style.start < codeBlockSpan.end && style.end > codeBlockSpan.start;
expect(overlaps).toBe(false);
}
});
});