-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathrenderers.test.js
More file actions
94 lines (83 loc) · 3.29 KB
/
Copy pathrenderers.test.js
File metadata and controls
94 lines (83 loc) · 3.29 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
import { expect } from '@esm-bundle/chai';
import { parseDirectives } from '../../../../nx2/blocks/chat/utils/parse.js';
describe('parseDirectives', () => {
describe('plain text', () => {
it('returns a single text segment for plain text', () => {
const result = parseDirectives('hello world');
expect(result).to.deep.equal([{ kind: 'text', content: 'hello world' }]);
});
it('returns empty array for empty string', () => {
expect(parseDirectives('')).to.deep.equal([]);
});
});
describe('single directive', () => {
it('parses a basic directive', () => {
const text = ':::checklist\n- [x] Done\n:::';
expect(parseDirectives(text)).to.deep.equal([
{ kind: 'directive', type: 'checklist', content: '- [x] Done' },
]);
});
it('parses a hyphenated type', () => {
const text = ':::alert-error\nSomething failed.\n:::';
expect(parseDirectives(text)).to.deep.equal([
{ kind: 'directive', type: 'alert-error', content: 'Something failed.' },
]);
});
});
describe('mixed content', () => {
it('handles text before a directive', () => {
const text = 'Intro text.\n:::list\n- item\n:::';
const result = parseDirectives(text);
expect(result).to.deep.equal([
{ kind: 'text', content: 'Intro text.' },
{ kind: 'directive', type: 'list', content: '- item' },
]);
});
it('handles text after a directive', () => {
const text = ':::list\n- item\n:::\nTrailing text.';
const result = parseDirectives(text);
expect(result).to.deep.equal([
{ kind: 'directive', type: 'list', content: '- item' },
{ kind: 'text', content: 'Trailing text.' },
]);
});
it('handles multiple directives', () => {
const text = ':::list\n- a\n:::\n:::checklist\n- [x] b\n:::';
const result = parseDirectives(text);
expect(result).to.deep.equal([
{ kind: 'directive', type: 'list', content: '- a' },
{ kind: 'directive', type: 'checklist', content: '- [x] b' },
]);
});
});
describe('bare ::: with no type', () => {
it('treats ::: with no type as plain text', () => {
expect(parseDirectives(':::')).to.deep.equal([{ kind: 'text', content: ':::' }]);
});
it('does not open a directive scope for bare :::', () => {
const text = ':::\n:::checklist\n- item\n:::';
const result = parseDirectives(text);
expect(result).to.deep.equal([
{ kind: 'text', content: ':::' },
{ kind: 'directive', type: 'checklist', content: '- item' },
]);
});
});
describe('unclosed directive (streaming)', () => {
it('renders an unclosed directive as a directive with partial content', () => {
const text = ':::checklist\n- [x] partial';
const result = parseDirectives(text);
expect(result).to.deep.equal([
{ kind: 'directive', type: 'checklist', content: '- [x] partial' },
]);
});
it('renders completed and unclosed directives in order', () => {
const text = ':::list\n- done\n:::\n:::checklist\n- partial';
const result = parseDirectives(text);
expect(result).to.deep.equal([
{ kind: 'directive', type: 'list', content: '- done' },
{ kind: 'directive', type: 'checklist', content: '- partial' },
]);
});
});
});