|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- import getParser from '../../src/parser/block-parser';
- import { Line } from '../../src/primitives';
- import { seedTokens } from '../../src/util';
-
- let source: Line[];
-
- beforeEach(() => {
- source = [
- {
- number: 1,
- source: ' /**',
- tokens: seedTokens({
- start: ' ',
- delimiter: '/**',
- postDelimiter: '',
- description: '',
- end: '',
- }),
- },
- {
- number: 2,
- source: ' * description 0',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- description: 'description 0',
- end: '',
- }),
- },
- {
- number: 3,
- source: ' *',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: '',
- description: '',
- end: '',
- }),
- },
- {
- number: 4,
- source: ' * description 1',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- description: 'description 1',
- end: '',
- }),
- },
- {
- number: 5,
- source: ' *',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: '',
- description: '',
- end: '',
- }),
- },
- {
- number: 6,
- source: ' * @param {string} value value description 0',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- description: '@param {string} value value description 0',
- end: '',
- }),
- },
- {
- number: 7,
- source: ' ```',
- tokens: seedTokens({
- start: ' ',
- delimiter: '',
- postDelimiter: '',
- description: '```',
- end: '',
- }),
- },
- {
- number: 8,
- source: ' @sample code',
- tokens: seedTokens({
- start: ' ',
- delimiter: '',
- postDelimiter: '',
- description: '@sample code',
- end: '',
- }),
- },
- {
- number: 9,
- source: ' ```',
- tokens: seedTokens({
- start: ' ',
- delimiter: '',
- postDelimiter: '',
- description: '```',
- end: '',
- }),
- },
- {
- number: 10,
- source: ' * value description 1',
- tokens: seedTokens({
- start: ' ',
- delimiter: '*',
- postDelimiter: ' ',
- description: 'value description 1',
- end: '',
- }),
- },
- {
- number: 11,
- source: ' */',
- tokens: seedTokens({
- start: ' ',
- delimiter: '',
- postDelimiter: '',
- description: '',
- end: '*/',
- }),
- },
- ];
- });
-
- test('standard fences', () => {
- const parser = getParser();
- const groups: Line[][] = parser(source);
-
- expect(groups.length).toBe(2);
- expect(groups).toEqual([source.slice(0, 5), source.slice(5)]);
- });
-
- test('custom fence', () => {
- source = source.map((line) => {
- line.tokens.description = line.tokens.description.replace('```', '###');
- return line;
- });
-
- const parser = getParser({ fence: '###' });
- const groups: Line[][] = parser(source);
-
- expect(groups.length).toBe(2);
- expect(groups).toEqual([source.slice(0, 5), source.slice(5)]);
- });
-
- test('fence function', () => {
- source = source.map((line) => {
- line.tokens.description = line.tokens.description.replace('```', '###');
- return line;
- });
-
- function isFenced(source: string) {
- return source.split('###').length % 2 === 0;
- }
-
- const parser = getParser({ fence: isFenced });
- const groups: Line[][] = parser(source);
-
- expect(groups.length).toBe(2);
- expect(groups).toEqual([source.slice(0, 5), source.slice(5)]);
- });
|