|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- import getParser from '../../src/parser';
- import { seedTokens } from '../../src/util';
-
- test('block with tags', () => {
- const parsed = getParser()(`
- /**
- * Description may go
- * over few lines followed by @tags
- * @param {string} name name parameter
- *
- * @param {any} value value of any type
- */`);
- expect(parsed).toEqual([
- {
- description: 'Description may go over few lines followed by @tags',
- tags: [
- {
- tag: 'param',
- name: 'name',
- type: 'string',
- optional: false,
- description: 'name parameter',
- problems: [],
- source: [
- {
- number: 4,
- source: ' * @param {string} name name parameter',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- tag: '@param',
- postTag: ' ',
- name: 'name',
- postName: ' ',
- type: '{string}',
- postType: ' ',
- description: 'name parameter',
- }),
- },
- {
- number: 5,
- source: ' *',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- }),
- },
- ],
- },
- {
- tag: 'param',
- name: 'value',
- type: 'any',
- optional: false,
- description: 'value of any type',
- problems: [],
- source: [
- {
- number: 6,
- source: ' * @param {any} value value of any type',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- tag: '@param',
- postTag: ' ',
- name: 'value',
- postName: ' ',
- type: '{any}',
- postType: ' ',
- description: 'value of any type',
- }),
- },
- {
- number: 7,
- source: ' */',
- tokens: seedTokens({
- start: ' ',
- end: '*/',
- }),
- },
- ],
- },
- ],
- source: [
- {
- number: 1,
- source: ' /**',
- tokens: seedTokens({
- start: ' ',
- delimiter: '/**',
- }),
- },
- {
- number: 2,
- source: ' * Description may go ',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- description: 'Description may go ',
- }),
- },
- {
- number: 3,
- source: ' * over few lines followed by @tags',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- description: 'over few lines followed by @tags',
- }),
- },
- {
- number: 4,
- source: ' * @param {string} name name parameter',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- tag: '@param',
- postTag: ' ',
- name: 'name',
- postName: ' ',
- type: '{string}',
- postType: ' ',
- description: 'name parameter',
- end: '',
- }),
- },
- {
- number: 5,
- source: ' *',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- }),
- },
- {
- number: 6,
- source: ' * @param {any} value value of any type',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- tag: '@param',
- postTag: ' ',
- name: 'value',
- postName: ' ',
- type: '{any}',
- postType: ' ',
- description: 'value of any type',
- }),
- },
- {
- number: 7,
- source: ' */',
- tokens: seedTokens({
- start: ' ',
- end: '*/',
- }),
- },
- ],
- problems: [],
- },
- ]);
- });
-
- test('no source clonning', () => {
- const parsed = getParser()(`
- /**
- * Description may go
- * over few lines followed by @tags
- * @param {string} name name parameter
- *
- * @param {any} value value of any type
- */`);
- expect(parsed[0].tags[0].source[0] === parsed[0].source[3]).toBe(true);
- });
-
- test.each([
- ['empty', '/**\n*\n*/'],
- ['one-star', '/*\n*\n*/'],
- ['three-star', '/***\n*\n*/'],
- ['empty one-liner', '/** */'],
- ['one-star oneliner', '/* */'],
- ['three-star oneliner', '/*** */'],
- ])('skip block - %s', (name, source) => {
- expect(getParser()(source)).toEqual([]);
- });
-
- test.each([
- ['negative', -1],
- ['float', 1.5],
- ])('invalid start line - %s', (name, startLine) => {
- expect(() => getParser({ startLine })).toThrow('Invalid startLine');
- });
|