|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | + |
| 4 | +import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs'; |
| 5 | +import { u } from 'unist-builder'; |
| 6 | + |
| 7 | +import { generate } from '../generate.mjs'; |
| 8 | + |
| 9 | +const config = await setConfig({ target: ['man-page'] }); |
| 10 | +config['man-page'].output = undefined; |
| 11 | + |
| 12 | +const entry = (depth, slug, text, description = '') => { |
| 13 | + const heading = u('heading', { depth }, [u('text', text)]); |
| 14 | + |
| 15 | + return { |
| 16 | + heading: { depth, data: { slug, text } }, |
| 17 | + content: u('root', [heading, u('paragraph', [u('text', description)])]), |
| 18 | + }; |
| 19 | +}; |
| 20 | + |
| 21 | +describe('man-page generate', () => { |
| 22 | + it('keeps the last environment variable when the section ends the input', async () => { |
| 23 | + const input = [ |
| 24 | + entry(1, 'command-line-api', 'Command-line API'), |
| 25 | + entry(2, 'environment-variables', 'Environment variables', 'Intro.'), |
| 26 | + entry(2, 'options', 'Options'), |
| 27 | + entry(3, '--foo', '`--foo`', 'Foo option.'), |
| 28 | + entry(2, 'environment-variables-1', 'Environment variables'), |
| 29 | + entry(3, 'node_onevalue', '`NODE_ONE=value`', 'First var.'), |
| 30 | + entry(3, 'node_twovalue', '`NODE_TWO=value`', 'Second var.'), |
| 31 | + entry(3, 'node_threevalue', '`NODE_THREE=value`', 'Third var.'), |
| 32 | + ]; |
| 33 | + |
| 34 | + const output = await generate(input); |
| 35 | + |
| 36 | + assert.match(output, /\.It Ev NODE_ONE Ar value\nFirst var\./); |
| 37 | + assert.match(output, /\.It Ev NODE_TWO Ar value\nSecond var\./); |
| 38 | + assert.match(output, /\.It Ev NODE_THREE Ar value\nThird var\./); |
| 39 | + }); |
| 40 | + |
| 41 | + it('stops the environment variables at the next section', async () => { |
| 42 | + const input = [ |
| 43 | + entry(2, 'options', 'Options'), |
| 44 | + entry(3, '--foo', '`--foo`', 'Foo option.'), |
| 45 | + entry(2, 'environment-variables-1', 'Environment variables'), |
| 46 | + entry(3, 'node_onevalue', '`NODE_ONE=value`', 'First var.'), |
| 47 | + entry(2, 'useful-v8-options', 'Useful V8 options'), |
| 48 | + entry(3, '--max-old-space-size', '`--max-old-space-size=SIZE`', 'Heap.'), |
| 49 | + ]; |
| 50 | + |
| 51 | + const output = await generate(input); |
| 52 | + |
| 53 | + assert.match(output, /\.It Ev NODE_ONE Ar value\nFirst var\./); |
| 54 | + assert.doesNotMatch(output, /max-old-space-size/); |
| 55 | + }); |
| 56 | +}); |
0 commit comments