Skip to content

Commit

Permalink
test: add block-parsers test (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon authored May 10, 2024
1 parent 8549db8 commit a71168f
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions src/__tests__/block-parsers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import MarkdownIt from 'markdown-it';
import { parseMethodBlocks } from '../block-parsers';

describe('block parsers', () => {
it('should parse a method', async () => {
const md = new MarkdownIt();
const contents = `
# \`test.foo(x)\`
* \`x\` Integer - x
`;

const allTokens = md.parse(contents, {});

expect(parseMethodBlocks(allTokens)).toEqual([
{
additionalTags: [],
description: '',
name: 'foo',
parameters: [
{
collection: false,
description: 'x',
name: 'x',
required: true,
type: 'Integer',
},
],
rawGenerics: undefined,
returns: null,
signature: '(x)',
urlFragment: '#testfoox',
},
]);
});

it('should parse a method with optional parameters', async () => {
const md = new MarkdownIt();
const contents = `
# \`test.foo([x])\`
* \`x\` Integer (optional) - x
`;

const allTokens = md.parse(contents, {});

expect(parseMethodBlocks(allTokens)).toEqual([
{
additionalTags: [],
description: '',
name: 'foo',
parameters: [
{
collection: false,
description: 'x',
name: 'x',
required: false,
type: 'Integer',
},
],
rawGenerics: undefined,
returns: null,
signature: '([x])',
urlFragment: '#testfoox',
},
]);
});

it('should parse a method with a parameter that can be an object or an integer', async () => {
const md = new MarkdownIt();
const contents = `
# \`test.foo([x])\`
* \`x\` Object | Integer (optional) - x
* \`y\` Integer - y
`;

const allTokens = md.parse(contents, {});

expect(parseMethodBlocks(allTokens)).toEqual([
{
additionalTags: [],
description: '',
name: 'foo',
parameters: [
{
collection: false,
description: 'x',
name: 'x',
required: false,
type: [
{
collection: false,
properties: [
{
additionalTags: [],
collection: false,
description: 'y',
name: 'y',
required: true,
type: 'Integer',
},
],
type: 'Object',
},
{
collection: false,
type: 'Integer',
},
],
},
],
rawGenerics: undefined,
returns: null,
signature: '([x])',
urlFragment: '#testfoox',
},
]);
});
});

0 comments on commit a71168f

Please sign in to comment.