forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.mjs
More file actions
98 lines (85 loc) · 2.93 KB
/
index.test.mjs
File metadata and controls
98 lines (85 loc) · 2.93 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
import { strictEqual, deepStrictEqual } from 'node:assert';
import { describe, it } from 'node:test';
import {
parseYAMLIntoMetadata,
transformTypeToReferenceLink,
parseHeadingIntoMetadata,
normalizeYamlSyntax,
} from '../index.mjs';
describe('transformTypeToReferenceLink', () => {
it('should transform a JavaScript primitive type into a Markdown link', () => {
strictEqual(
transformTypeToReferenceLink('string'),
'[`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)'
);
});
it('should transform a JavaScript global type into a Markdown link', () => {
strictEqual(
transformTypeToReferenceLink('Array'),
'[`<Array>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)'
);
});
});
describe('normalizeYamlSyntax', () => {
it('should normalize YAML syntax by fixing noncompliant properties', () => {
const input = `introduced_in=v0.1.21
source_link=lib/test.js
type=module
name=test_module
llmDescription: This is a test module`;
const normalizedYaml = normalizeYamlSyntax(input);
strictEqual(
normalizedYaml,
`introduced_in: v0.1.21
source_link: lib/test.js
type: module
name: test_module
llmDescription: This is a test module`
);
});
it('should remove leading and trailing newlines', () => {
const input = '\nintroduced_in=v0.1.21\n';
const normalizedYaml = normalizeYamlSyntax(input);
strictEqual(normalizedYaml, 'introduced_in: v0.1.21');
});
});
describe('parseYAMLIntoMetadata', () => {
it('should parse a YAML string into a JavaScript object', () => {
const input = 'name: test\ntype: module\nintroduced_in: v1.0.0';
const expectedOutput = {
name: 'test',
type: 'module',
introduced_in: 'v1.0.0',
};
deepStrictEqual(parseYAMLIntoMetadata(input), expectedOutput);
});
it('should parse a YAML string with multiple versions into a JavaScript object', () => {
const input = 'name: test\ntype: module\nintroduced_in: [v1.0.0, v1.1.0]';
const expectedOutput = {
name: 'test',
type: 'module',
introduced_in: ['v1.0.0', 'v1.1.0'],
};
deepStrictEqual(parseYAMLIntoMetadata(input), expectedOutput);
});
it('should parse a YAML string with source_link into a JavaScript object', () => {
const input =
'name: test\ntype: module\nintroduced_in: v1.0.0\nsource_link: https://github.com/nodejs/node';
const expectedOutput = {
name: 'test',
type: 'module',
introduced_in: 'v1.0.0',
source_link: 'https://github.com/nodejs/node',
};
deepStrictEqual(parseYAMLIntoMetadata(input), expectedOutput);
});
it('should parse a raw Heading string into Heading metadata', () => {
const input = '## test';
const expectedOutput = {
text: '## test',
name: '## test',
depth: 2,
};
deepStrictEqual(parseHeadingIntoMetadata(input, 2), expectedOutput);
});
});