Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add block-parsers test #111

Merged
merged 2 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
},
]);
});
});