Skip to content

Commit

Permalink
fix: support complex and nested inner types (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored Jun 3, 2019
1 parent 5bcfc94 commit b2d95bf
Show file tree
Hide file tree
Showing 3 changed files with 414 additions and 13 deletions.
282 changes: 282 additions & 0 deletions src/__tests__/__snapshots__/markdown-helpers.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,287 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`markdown-helpers rawTypeToTypeInformation() should map a Promise types correctly 1`] = `
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": "T",
},
],
"type": "Promise",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a complex Promise types correctly 1`] = `
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": Array [
Object {
"collection": false,
"type": "T",
},
Object {
"collection": false,
"type": "A",
},
],
},
],
"type": "Promise",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a function return type + param types correctly 1`] = `
Object {
"collection": false,
"parameters": Array [
Object {
"collection": false,
"type": "P1",
},
Object {
"collection": false,
"type": "P2",
},
],
"returns": Object {
"collection": false,
"type": "R",
},
"type": "Function",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a function return type correctly 1`] = `
Object {
"collection": false,
"parameters": Array [],
"returns": Object {
"collection": false,
"type": "R",
},
"type": "Function",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a function with complex return type + complex param types correctly 1`] = `
Object {
"collection": false,
"parameters": Array [
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": "InnerP1",
},
Object {
"collection": true,
"type": "AnotherInnerP1",
},
],
"type": "P1",
},
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": true,
"type": Array [
Object {
"collection": false,
"type": "InnerP2",
},
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": "SuperDeepP2",
},
Object {
"collection": false,
"type": "EvenDeeperP2",
},
],
"type": "AnotherInnerP2",
},
],
},
],
"type": "P2",
},
],
"returns": Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": "Foo",
},
],
"type": "R",
},
"type": "Function",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Function types correctly 1`] = `
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": Array [
Object {
"collection": false,
"type": "T",
},
Object {
"collection": true,
"parameters": Array [],
"returns": Object {
"collection": true,
"type": "A",
},
"type": "Function",
},
],
},
],
"type": "Promise",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Promise types correctly 1`] = `
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": Array [
Object {
"collection": false,
"type": "T",
},
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": "A",
},
],
"type": "Promise",
},
],
},
],
"type": "Promise",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 1`] = `
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": Array [
Object {
"collection": false,
"type": "T",
},
Object {
"collection": true,
"innerTypes": Array [
Object {
"collection": true,
"type": "A",
},
],
"type": "Promise",
},
],
},
],
"type": "Promise",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 2`] = `
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": false,
"type": Array [
Object {
"collection": false,
"type": "T",
},
Object {
"collection": true,
"innerTypes": Array [
Object {
"collection": true,
"type": "A",
},
],
"type": "Promise",
},
],
},
],
"type": "Promise",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a primitive types correctly 1`] = `
Object {
"collection": false,
"type": "Boolean",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a wrapped collection type correctly 1`] = `
Object {
"collection": false,
"innerTypes": Array [
Object {
"collection": true,
"type": Array [
Object {
"collection": false,
"type": "T",
},
Object {
"collection": false,
"parameters": Array [],
"returns": Object {
"collection": true,
"type": "A",
},
"type": "Function",
},
],
},
],
"type": "Promise",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map an unknown types correctly 1`] = `
Object {
"collection": false,
"type": "MyType",
}
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for basic-paragraph 1`] = `"This is just a basic paragraph. It has multiple sentences and natural soft breaks."`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for blockquotes 1`] = `
Expand Down
60 changes: 59 additions & 1 deletion src/__tests__/markdown-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import MarkdownIt from 'markdown-it';

import { safelyJoinTokens, extractStringEnum } from '../markdown-helpers';
import { safelyJoinTokens, extractStringEnum, rawTypeToTypeInformation } from '../markdown-helpers';

describe('markdown-helpers', () => {
describe('safelyJoinTokens', () => {
Expand Down Expand Up @@ -86,4 +86,62 @@ describe('markdown-helpers', () => {
expect(values[2].value).toBe('c');
});
});

describe('rawTypeToTypeInformation()', () => {
it('should map a primitive types correctly', () => {
expect(rawTypeToTypeInformation('Boolean', '', null)).toMatchSnapshot();
});

it('should map an unknown types correctly', () => {
expect(rawTypeToTypeInformation('MyType', '', null)).toMatchSnapshot();
});

it('should map a Promise types correctly', () => {
expect(rawTypeToTypeInformation('Promise<T>', '', null)).toMatchSnapshot();
});

it('should map a complex Promise types correctly', () => {
expect(rawTypeToTypeInformation('Promise<T | A>', '', null)).toMatchSnapshot();
});

it('should map a nested Promise types correctly', () => {
expect(rawTypeToTypeInformation('Promise<T | Promise<A>>', '', null)).toMatchSnapshot();
});

it('should map a nested complex Promise types correctly', () => {
expect(rawTypeToTypeInformation('Promise<T | Promise<A[]>[]>', '', null)).toMatchSnapshot();
});

it('should map a nested complex Promise types correctly', () => {
expect(rawTypeToTypeInformation('Promise<T | Promise<A[]>[]>', '', null)).toMatchSnapshot();
});

it('should map a nested Function types correctly', () => {
expect(rawTypeToTypeInformation('Promise<T | Function<A[]>[]>', '', null)).toMatchSnapshot();
});

it('should map a wrapped collection type correctly', () => {
expect(
rawTypeToTypeInformation('Promise<(T | Function<A[]>)[]>', '', null),
).toMatchSnapshot();
});

it('should map a function return type correctly', () => {
expect(rawTypeToTypeInformation('Function<R>', '', null)).toMatchSnapshot();
});

it('should map a function return type + param types correctly', () => {
expect(rawTypeToTypeInformation('Function<P1, P2, R>', '', null)).toMatchSnapshot();
});

it('should map a function with complex return type + complex param types correctly', () => {
expect(
rawTypeToTypeInformation(
'Function<P1<InnerP1, AnotherInnerP1[]>, P2<(InnerP2 | AnotherInnerP2<SuperDeepP2, EvenDeeperP2>)[]>, R<Foo>>',
'',
null,
),
).toMatchSnapshot();
});
});
});
Loading

0 comments on commit b2d95bf

Please sign in to comment.