|
| 1 | +/*eslint max-len: 0 */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +var formatType = require('../index').formatType, |
| 5 | + mdast = require('mdast'), |
| 6 | + parseParamType = require('doctrine/lib/typed').parseParamType, |
| 7 | + test = require('tap').test; |
| 8 | + |
| 9 | +test('formatType', function (t) { |
| 10 | + [ |
| 11 | + ['Foo', 'Foo'], |
| 12 | + ['null', 'null'], |
| 13 | + ['null', 'null'], |
| 14 | + ['*', 'Any'], |
| 15 | + ['Array|undefined', '([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)|[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined))'], |
| 16 | + ['Array<number>', '[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>'], |
| 17 | + ['number!', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)!'], |
| 18 | + ['function(string, boolean)', 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean))'], |
| 19 | + ['function(string, boolean): number', 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)): [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'], |
| 20 | + ['function()', 'function ()'], |
| 21 | + ['function(this:something, string)', 'function (this: something, [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))'], |
| 22 | + ['function(new:something)', 'function (new: something)'], |
| 23 | + ['{myNum: number, myObject}', '{myNum: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), myObject}'], |
| 24 | + ['[string,]', '[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]'], |
| 25 | + ['number?', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?'], |
| 26 | + ['?number', '?[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'], |
| 27 | + ['?', '?'], |
| 28 | + ['void', 'void'], |
| 29 | + ['function(a:b)', 'function (a: b)'], |
| 30 | + ['function(a):void', 'function (a): void'], |
| 31 | + ['number=', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)='], |
| 32 | + ['...number', '...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'], |
| 33 | + ['undefined', '[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)'] |
| 34 | + ].forEach(function (example) { |
| 35 | + t.deepEqual(mdast().stringify({ |
| 36 | + type: 'paragraph', |
| 37 | + children: formatType(parseParamType(example[0])) |
| 38 | + }), example[1], example[0]); |
| 39 | + }); |
| 40 | + |
| 41 | + t.deepEqual(formatType(), [], 'empty case'); |
| 42 | + |
| 43 | + t.throws(function () { |
| 44 | + formatType({}); |
| 45 | + }); |
| 46 | + |
| 47 | + t.end(); |
| 48 | +}); |
0 commit comments