-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathblockSplitter.spec.ts
More file actions
118 lines (104 loc) · 4.25 KB
/
blockSplitter.spec.ts
File metadata and controls
118 lines (104 loc) · 4.25 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { BlockSplitter, BlockType } from '../src/BlockSplitter';
describe('BlockSplitter', () => {
it('should split simple paragraphs', () => {
const input = 'Hello\nWorld';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].type).toBe(BlockType.PARAGRAPH);
expect(blocks[0].content).toBe('Hello\nWorld');
});
it('should identify headings', () => {
const input = '# Heading 1\n## Heading 2\nContent';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(3);
expect(blocks[0].type).toBe(BlockType.HEADING);
expect(blocks[0].level).toBe(1);
expect(blocks[1].type).toBe(BlockType.HEADING);
expect(blocks[1].level).toBe(2);
});
it('should identify code blocks', () => {
const input = 'Pre\n```javascript\nconst a = 1;\n```\nPost';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(3);
expect(blocks[1].type).toBe(BlockType.CODE);
expect(blocks[1].language).toBe('javascript');
expect(blocks[1].content).toBe('const a = 1;');
});
it('should handle list splitting and preserve full syntax', () => {
const input = '- item 1\n* item 2\n1. item 3';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].type).toBe(BlockType.LIST);
expect(blocks[0].content).toBe('- item 1\n* item 2\n1. item 3');
});
it('should handle nested lists via indentation', () => {
const input = '- Level 1\n - Level 2\n - Level 3';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].content).toBe('- Level 1\n - Level 2\n - Level 3');
});
it('should allow indented blank lines to continue a list', () => {
const input = '- item 1\n \n- item 2';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].content).toBe('- item 1\n \n- item 2');
});
it('should correctly detect boundaries: list followed by heading', () => {
const input = '- list item\n\n# Heading';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(2);
expect(blocks[0].type).toBe(BlockType.LIST);
expect(blocks[1].type).toBe(BlockType.HEADING);
});
it('should identify blockquotes and preserve markers', () => {
const input = '> quote line 1\n> quote line 2';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].type).toBe(BlockType.QUOTE);
expect(blocks[0].content).toBe('> quote line 1\n> quote line 2');
});
it('should support nested blockquotes', () => {
const input = '> outer\n>> inner';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].type).toBe(BlockType.QUOTE);
expect(blocks[0].content).toBe('> outer\n>> inner');
});
it('should set ordered to undefined for mixed ordered and unordered list items', () => {
const input = '- unordered\n1. ordered';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].type).toBe(BlockType.LIST);
expect(blocks[0].ordered).toBeUndefined();
});
it('should keep ordered=true for fully ordered lists', () => {
const input = '1. first\n2. second';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].type).toBe(BlockType.LIST);
expect(blocks[0].ordered).toBe(true);
});
it('should keep ordered=false for fully unordered lists', () => {
const input = '- first\n* second';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(1);
expect(blocks[0].type).toBe(BlockType.LIST);
expect(blocks[0].ordered).toBe(false);
});
it('should create a new paragraph block after a list block', () => {
const input = '- list item\n\nParagraph text';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(2);
expect(blocks[0].type).toBe(BlockType.LIST);
expect(blocks[1].type).toBe(BlockType.PARAGRAPH);
expect(blocks[1].content).toBe('Paragraph text');
});
it('should create a new paragraph block after a quote block', () => {
const input = '> blockquote\n\nParagraph text';
const blocks = BlockSplitter.split(input);
expect(blocks.length).toBe(2);
expect(blocks[0].type).toBe(BlockType.QUOTE);
expect(blocks[1].type).toBe(BlockType.PARAGRAPH);
expect(blocks[1].content).toBe('Paragraph text');
});
});