forked from gajus/eslint-plugin-jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsdocUtils.js
105 lines (102 loc) · 3.34 KB
/
jsdocUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* eslint-disable max-nested-callbacks */
import {
expect,
} from 'chai';
import jsdocUtils from '../src/jsdocUtils';
describe('jsdocUtils', () => {
describe('getPreferredTagName()', () => {
context('no preferences', () => {
context('alias name', () => {
it('returns the primary tag name', () => {
expect(jsdocUtils.getPreferredTagName({}, 'jsdoc', 'return')).to.equal('returns');
});
});
it('returns the primary tag name', () => {
expect(jsdocUtils.getPreferredTagName({}, 'jsdoc', 'returns')).to.equal('returns');
});
});
context('with preferences', () => {
it('returns the preferred tag name', () => {
expect(jsdocUtils.getPreferredTagName({}, 'jsdoc', 'return', {returns: 'return'})).to.equal('return');
});
});
});
describe('isValidTag()', () => {
context('tag is invalid', () => {
it('returns false', () => {
expect(jsdocUtils.isValidTag({}, 'jsdoc', 'foo', [])).to.equal(false);
});
});
context('tag is valid', () => {
it('returns true', () => {
expect(jsdocUtils.isValidTag({}, 'jsdoc', 'param', [])).to.equal(true);
});
});
context('tag is valid alias', () => {
it('returns true', () => {
expect(jsdocUtils.isValidTag({}, 'jsdoc', 'arg', [])).to.equal(true);
});
});
context('tag is valid and customized', () => {
it('returns true', () => {
expect(jsdocUtils.isValidTag({}, 'jsdoc', 'foobar', ['foobar'])).to.equal(true);
});
});
});
describe('getFunctionParameterNames()', () => {
context('Unhandled param type', () => {
it('should throw with an unknown param type', () => {
expect(() => {
jsdocUtils.getFunctionParameterNames({params: [
{
type: 'AssignmentPattern',
},
]});
}).to.throw('Unsupported function signature format: `AssignmentPattern`.');
});
});
});
describe('hasDefinedTypeTag()', () => {
context('Missing tag', () => {
it('should return `false` with a missing tag', () => {
expect(jsdocUtils.hasDefinedTypeTag(null)).to.equal(false);
});
});
});
describe('flattenRoots()', () => {
context('Provided root', () => {
it('should prepend properties with provided root', () => {
const roots = [['data', ['last_modified']], ['options', ['headers']]];
const expected = {
hasPropertyRest: false,
hasRestElement: false,
names: ['base.data', 'base.data.last_modified', 'base.options', 'base.options.headers'],
rests: [
false,
false,
false,
false,
],
};
expect(jsdocUtils.flattenRoots(roots, 'base')).to.deep.equal(expected);
});
});
context('Without root', () => {
it('should prepend properties with provided root', () => {
const roots = [['data', ['last_modified']], ['options', ['headers']]];
const expected = {
hasPropertyRest: false,
hasRestElement: false,
names: ['data', 'data.last_modified', 'options', 'options.headers'],
rests: [
false,
false,
false,
false,
],
};
expect(jsdocUtils.flattenRoots(roots)).to.deep.equal(expected);
});
});
});
});