11cb0ef41Sopenharmony_ciimport * as common from '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport * as fixtures from '../common/fixtures.mjs';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciimport assert from 'assert';
51cb0ef41Sopenharmony_ciimport fs from 'fs';
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciimport * as json from '../../tools/doc/json.mjs';
81cb0ef41Sopenharmony_ciimport {
91cb0ef41Sopenharmony_ci  remarkParse,
101cb0ef41Sopenharmony_ci  unified,
111cb0ef41Sopenharmony_ci} from '../../tools/doc/deps.mjs';
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cifunction toJSON(input, filename, cb) {
141cb0ef41Sopenharmony_ci  function nullCompiler() {
151cb0ef41Sopenharmony_ci    this.Compiler = (tree) => tree;
161cb0ef41Sopenharmony_ci  }
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  unified()
191cb0ef41Sopenharmony_ci    .use(remarkParse)
201cb0ef41Sopenharmony_ci    .use(json.jsonAPI, { filename })
211cb0ef41Sopenharmony_ci    .use(nullCompiler)
221cb0ef41Sopenharmony_ci    .process(input, cb);
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci// Outputs valid json with the expected fields when given simple markdown
261cb0ef41Sopenharmony_ci// Test data is a list of objects with two properties.
271cb0ef41Sopenharmony_ci// The file property is the file path.
281cb0ef41Sopenharmony_ci// The json property is some json which will be generated by the doctool.
291cb0ef41Sopenharmony_ciconst testData = [
301cb0ef41Sopenharmony_ci  {
311cb0ef41Sopenharmony_ci    file: fixtures.path('sample_document.md'),
321cb0ef41Sopenharmony_ci    json: {
331cb0ef41Sopenharmony_ci      type: 'module',
341cb0ef41Sopenharmony_ci      source: 'foo',
351cb0ef41Sopenharmony_ci      modules: [{
361cb0ef41Sopenharmony_ci        textRaw: 'Sample Markdown',
371cb0ef41Sopenharmony_ci        name: 'sample_markdown',
381cb0ef41Sopenharmony_ci        modules: [{
391cb0ef41Sopenharmony_ci          textRaw: 'Seussian Rhymes',
401cb0ef41Sopenharmony_ci          name: 'seussian_rhymes',
411cb0ef41Sopenharmony_ci          desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' +
421cb0ef41Sopenharmony_ci                  '<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>',
431cb0ef41Sopenharmony_ci          type: 'module',
441cb0ef41Sopenharmony_ci          displayName: 'Seussian Rhymes',
451cb0ef41Sopenharmony_ci        }],
461cb0ef41Sopenharmony_ci        type: 'module',
471cb0ef41Sopenharmony_ci        displayName: 'Sample Markdown',
481cb0ef41Sopenharmony_ci      }],
491cb0ef41Sopenharmony_ci    },
501cb0ef41Sopenharmony_ci  },
511cb0ef41Sopenharmony_ci  {
521cb0ef41Sopenharmony_ci    file: fixtures.path('order_of_end_tags_5873.md'),
531cb0ef41Sopenharmony_ci    json: {
541cb0ef41Sopenharmony_ci      type: 'module',
551cb0ef41Sopenharmony_ci      source: 'foo',
561cb0ef41Sopenharmony_ci      modules: [{
571cb0ef41Sopenharmony_ci        textRaw: 'Title',
581cb0ef41Sopenharmony_ci        name: 'title',
591cb0ef41Sopenharmony_ci        modules: [{
601cb0ef41Sopenharmony_ci          textRaw: 'Subsection',
611cb0ef41Sopenharmony_ci          name: 'subsection',
621cb0ef41Sopenharmony_ci          classMethods: [{
631cb0ef41Sopenharmony_ci            textRaw: 'Static method: Buffer.from(array)',
641cb0ef41Sopenharmony_ci            type: 'classMethod',
651cb0ef41Sopenharmony_ci            name: 'from',
661cb0ef41Sopenharmony_ci            signatures: [
671cb0ef41Sopenharmony_ci              {
681cb0ef41Sopenharmony_ci                params: [{
691cb0ef41Sopenharmony_ci                  textRaw: '`array` {Array}',
701cb0ef41Sopenharmony_ci                  name: 'array',
711cb0ef41Sopenharmony_ci                  type: 'Array',
721cb0ef41Sopenharmony_ci                }],
731cb0ef41Sopenharmony_ci              },
741cb0ef41Sopenharmony_ci            ],
751cb0ef41Sopenharmony_ci          }],
761cb0ef41Sopenharmony_ci          type: 'module',
771cb0ef41Sopenharmony_ci          displayName: 'Subsection',
781cb0ef41Sopenharmony_ci        }],
791cb0ef41Sopenharmony_ci        type: 'module',
801cb0ef41Sopenharmony_ci        displayName: 'Title',
811cb0ef41Sopenharmony_ci      }],
821cb0ef41Sopenharmony_ci    },
831cb0ef41Sopenharmony_ci  },
841cb0ef41Sopenharmony_ci  {
851cb0ef41Sopenharmony_ci    file: fixtures.path('doc_with_yaml.md'),
861cb0ef41Sopenharmony_ci    json: {
871cb0ef41Sopenharmony_ci      type: 'module',
881cb0ef41Sopenharmony_ci      source: 'foo',
891cb0ef41Sopenharmony_ci      modules: [
901cb0ef41Sopenharmony_ci        {
911cb0ef41Sopenharmony_ci          textRaw: 'Sample Markdown with YAML info',
921cb0ef41Sopenharmony_ci          name: 'sample_markdown_with_yaml_info',
931cb0ef41Sopenharmony_ci          modules: [
941cb0ef41Sopenharmony_ci            {
951cb0ef41Sopenharmony_ci              textRaw: 'Foobar',
961cb0ef41Sopenharmony_ci              name: 'foobar',
971cb0ef41Sopenharmony_ci              meta: {
981cb0ef41Sopenharmony_ci                added: ['v1.0.0'],
991cb0ef41Sopenharmony_ci                changes: [],
1001cb0ef41Sopenharmony_ci              },
1011cb0ef41Sopenharmony_ci              desc: '<p>Describe <code>Foobar</code> in more detail ' +
1021cb0ef41Sopenharmony_ci                'here.</p>',
1031cb0ef41Sopenharmony_ci              type: 'module',
1041cb0ef41Sopenharmony_ci              displayName: 'Foobar',
1051cb0ef41Sopenharmony_ci            },
1061cb0ef41Sopenharmony_ci            {
1071cb0ef41Sopenharmony_ci              textRaw: 'Foobar II',
1081cb0ef41Sopenharmony_ci              name: 'foobar_ii',
1091cb0ef41Sopenharmony_ci              meta: {
1101cb0ef41Sopenharmony_ci                added: ['v5.3.0', 'v4.2.0'],
1111cb0ef41Sopenharmony_ci                changes: [
1121cb0ef41Sopenharmony_ci                  { 'version': 'v4.2.0',
1131cb0ef41Sopenharmony_ci                    'pr-url': 'https://github.com/nodejs/node/pull/3276',
1141cb0ef41Sopenharmony_ci                    'description': 'The `error` parameter can now be ' +
1151cb0ef41Sopenharmony_ci                      'an arrow function.' },
1161cb0ef41Sopenharmony_ci                ],
1171cb0ef41Sopenharmony_ci              },
1181cb0ef41Sopenharmony_ci              desc: '<p>Describe <code>Foobar II</code> in more detail ' +
1191cb0ef41Sopenharmony_ci                'here. fg(1)</p>',
1201cb0ef41Sopenharmony_ci              type: 'module',
1211cb0ef41Sopenharmony_ci              displayName: 'Foobar II',
1221cb0ef41Sopenharmony_ci            },
1231cb0ef41Sopenharmony_ci            {
1241cb0ef41Sopenharmony_ci              textRaw: 'Deprecated thingy',
1251cb0ef41Sopenharmony_ci              name: 'deprecated_thingy',
1261cb0ef41Sopenharmony_ci              meta: {
1271cb0ef41Sopenharmony_ci                added: ['v1.0.0'],
1281cb0ef41Sopenharmony_ci                deprecated: ['v2.0.0'],
1291cb0ef41Sopenharmony_ci                changes: [],
1301cb0ef41Sopenharmony_ci              },
1311cb0ef41Sopenharmony_ci              desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
1321cb0ef41Sopenharmony_ci                'detail here. fg(1p)</p>',
1331cb0ef41Sopenharmony_ci              type: 'module',
1341cb0ef41Sopenharmony_ci              displayName: 'Deprecated thingy',
1351cb0ef41Sopenharmony_ci            },
1361cb0ef41Sopenharmony_ci            {
1371cb0ef41Sopenharmony_ci              textRaw: 'Something',
1381cb0ef41Sopenharmony_ci              name: 'something',
1391cb0ef41Sopenharmony_ci              desc: '<!-- This is not a metadata comment -->\n<p>' +
1401cb0ef41Sopenharmony_ci                'Describe <code>Something</code> in more detail here.</p>',
1411cb0ef41Sopenharmony_ci              type: 'module',
1421cb0ef41Sopenharmony_ci              displayName: 'Something',
1431cb0ef41Sopenharmony_ci            },
1441cb0ef41Sopenharmony_ci          ],
1451cb0ef41Sopenharmony_ci          type: 'module',
1461cb0ef41Sopenharmony_ci          displayName: 'Sample Markdown with YAML info',
1471cb0ef41Sopenharmony_ci        },
1481cb0ef41Sopenharmony_ci      ],
1491cb0ef41Sopenharmony_ci    },
1501cb0ef41Sopenharmony_ci  },
1511cb0ef41Sopenharmony_ci  {
1521cb0ef41Sopenharmony_ci    file: fixtures.path('doc_with_backticks_in_headings.md'),
1531cb0ef41Sopenharmony_ci    json: {
1541cb0ef41Sopenharmony_ci      type: 'module',
1551cb0ef41Sopenharmony_ci      source: 'foo',
1561cb0ef41Sopenharmony_ci      modules: [
1571cb0ef41Sopenharmony_ci        {
1581cb0ef41Sopenharmony_ci          textRaw: 'Fhqwhgads',
1591cb0ef41Sopenharmony_ci          name: 'fhqwhgads',
1601cb0ef41Sopenharmony_ci          properties: [
1611cb0ef41Sopenharmony_ci            {
1621cb0ef41Sopenharmony_ci              name: 'fullName',
1631cb0ef41Sopenharmony_ci              textRaw: '`Fqhqwhgads.fullName`',
1641cb0ef41Sopenharmony_ci            },
1651cb0ef41Sopenharmony_ci          ],
1661cb0ef41Sopenharmony_ci          classMethods: [
1671cb0ef41Sopenharmony_ci            {
1681cb0ef41Sopenharmony_ci              name: 'again',
1691cb0ef41Sopenharmony_ci              signatures: [
1701cb0ef41Sopenharmony_ci                {
1711cb0ef41Sopenharmony_ci                  params: [],
1721cb0ef41Sopenharmony_ci                },
1731cb0ef41Sopenharmony_ci              ],
1741cb0ef41Sopenharmony_ci              textRaw: 'Static method: `Fhqwhgads.again()`',
1751cb0ef41Sopenharmony_ci              type: 'classMethod',
1761cb0ef41Sopenharmony_ci            },
1771cb0ef41Sopenharmony_ci          ],
1781cb0ef41Sopenharmony_ci          classes: [
1791cb0ef41Sopenharmony_ci            {
1801cb0ef41Sopenharmony_ci              textRaw: 'Class: `ComeOn`',
1811cb0ef41Sopenharmony_ci              type: 'class',
1821cb0ef41Sopenharmony_ci              name: 'ComeOn',
1831cb0ef41Sopenharmony_ci            },
1841cb0ef41Sopenharmony_ci          ],
1851cb0ef41Sopenharmony_ci          ctors: [
1861cb0ef41Sopenharmony_ci            {
1871cb0ef41Sopenharmony_ci              name: 'Fhqwhgads',
1881cb0ef41Sopenharmony_ci              signatures: [
1891cb0ef41Sopenharmony_ci                {
1901cb0ef41Sopenharmony_ci                  params: [],
1911cb0ef41Sopenharmony_ci                },
1921cb0ef41Sopenharmony_ci              ],
1931cb0ef41Sopenharmony_ci              textRaw: 'Constructor: `new Fhqwhgads()`',
1941cb0ef41Sopenharmony_ci              type: 'ctor',
1951cb0ef41Sopenharmony_ci            },
1961cb0ef41Sopenharmony_ci          ],
1971cb0ef41Sopenharmony_ci          methods: [
1981cb0ef41Sopenharmony_ci            {
1991cb0ef41Sopenharmony_ci              textRaw: '`everybody.to(limit)`',
2001cb0ef41Sopenharmony_ci              type: 'method',
2011cb0ef41Sopenharmony_ci              name: 'to',
2021cb0ef41Sopenharmony_ci              signatures: [{ params: [] }],
2031cb0ef41Sopenharmony_ci            },
2041cb0ef41Sopenharmony_ci          ],
2051cb0ef41Sopenharmony_ci          events: [
2061cb0ef41Sopenharmony_ci            {
2071cb0ef41Sopenharmony_ci              textRaw: "Event: `'FHQWHfest'`",
2081cb0ef41Sopenharmony_ci              type: 'event',
2091cb0ef41Sopenharmony_ci              name: 'FHQWHfest',
2101cb0ef41Sopenharmony_ci              params: [],
2111cb0ef41Sopenharmony_ci            },
2121cb0ef41Sopenharmony_ci          ],
2131cb0ef41Sopenharmony_ci          type: 'module',
2141cb0ef41Sopenharmony_ci          displayName: 'Fhqwhgads',
2151cb0ef41Sopenharmony_ci        },
2161cb0ef41Sopenharmony_ci      ],
2171cb0ef41Sopenharmony_ci    },
2181cb0ef41Sopenharmony_ci  },
2191cb0ef41Sopenharmony_ci];
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_citestData.forEach((item) => {
2221cb0ef41Sopenharmony_ci  fs.readFile(item.file, 'utf8', common.mustSucceed((input) => {
2231cb0ef41Sopenharmony_ci    toJSON(input, 'foo', common.mustSucceed((output) => {
2241cb0ef41Sopenharmony_ci      assert.deepStrictEqual(output.json, item.json);
2251cb0ef41Sopenharmony_ci    }));
2261cb0ef41Sopenharmony_ci  }));
2271cb0ef41Sopenharmony_ci});
228