|
1 | | -import { strictEqual } from 'node:assert'; |
| 1 | +import { strictEqual, ok } from 'node:assert'; |
2 | 2 | import { describe, it } from 'node:test'; |
3 | 3 |
|
4 | 4 | import { u as createTree } from 'unist-builder'; |
5 | 5 |
|
6 | | -import { UNIST } from '../index.mjs'; |
| 6 | +import { QUERIES, UNIST } from '../index.mjs'; |
| 7 | + |
| 8 | +describe('QUERIES', () => { |
| 9 | + describe('standardYamlFrontmatter', () => { |
| 10 | + it('matches standard YAML frontmatter at the beginning of the text', () => { |
| 11 | + const content = '---\nintroduced_in: v1.0.0\ntype: module\n---'; |
| 12 | + ok(QUERIES.standardYamlFrontmatter.test(content)); |
| 13 | + |
| 14 | + const match = QUERIES.standardYamlFrontmatter.exec(content); |
| 15 | + strictEqual(match[1], 'introduced_in: v1.0.0\ntype: module'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('matches standard YAML frontmatter with Windows line endings (CRLF)', () => { |
| 19 | + const content = '---\r\nintroduced_in: v1.0.0\r\n---'; |
| 20 | + ok(QUERIES.standardYamlFrontmatter.test(content)); |
| 21 | + |
| 22 | + const match = QUERIES.standardYamlFrontmatter.exec(content); |
| 23 | + strictEqual(match[1], 'introduced_in: v1.0.0'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('does not match horizontal rules or dashes not at the start of the string', () => { |
| 27 | + const content = '# Hello\n\n---\n\nSome text'; |
| 28 | + strictEqual(QUERIES.standardYamlFrontmatter.test(content), false); |
| 29 | + }); |
| 30 | + |
| 31 | + it('does not match unclosed frontmatter blocks', () => { |
| 32 | + const content = '---\nintroduced_in: v1.0.0\nSome text...'; |
| 33 | + strictEqual(QUERIES.standardYamlFrontmatter.test(content), false); |
| 34 | + }); |
| 35 | + }); |
| 36 | +}); |
7 | 37 |
|
8 | 38 | describe('UNIST', () => { |
9 | 39 | describe('isStronglyTypedList', () => { |
|
0 commit comments