it('maps a DocumentEntity to a Document', function() { const documents = [ b.document({ id: 'Klass' }), b.documentEntity({ id: 'Method', }) ] const tree = subject({ id: 'foo', documents, treeOperations: [ { type: 'CHANGE_NODE_PARENT', data: { parentUid: uidOf('Klass', documents), uid: uidOf('Method', documents), }, } ] }) assert.equal(tree.documents.length, 1) assert.equal(tree.documents[0].id, 'Klass') assert.equal(tree.documents[0].entities.length, 1) assert.equal(tree.documents[0].entities[0].id, 'Method') });
it('wires documents nested inside namespaces to their namespace nodes', function() { const documents = [ b.document({ id: 'MyNamespace', properties: {} }), b.document({ id: 'truck', title: 'truck', properties: { namespace: 'MyNamespace', isModule: true } }), ]; const treeOperations = subject(defaultContext, documents) assert.equal(treeOperations.length, 2); assert.include(treeOperations[1].data, { uid: uidOf('truck', documents), parentUid: uidOf('MyNamespace', documents), }); });
it('sample 3: example with code only', function() { var tag = parse(function() {; // /** // * @example // * module.exports = { // * name: 'author.user', // * path: ':userId', // * parent: 'author.users' // * }; // * // * // visitable at "/author/users/1" or "/author/users/:userId" // */ }); assert.equal(tag.typeInfo.name, null); assert.deepEqual(tag.typeInfo.description, [ "", " module.exports = {", " name: 'author.user',", " path: ':userId',", " parent: 'author.users'", " };", "", " // visitable at \"/author/users/1\" or \"/author/users/:userId\"", "", ].join('\n')); });
it('wires entities to their parents', function() { const documents = [ b.document({ id: 'truck', title: 'truck', properties: { id: 'truck', isModule: true } }), b.documentEntity({ id: '#beep', properties: { receiver: 'truck' } }) ]; const treeOperations = subject(defaultContext, documents) assert.equal(treeOperations.length, 2); assert.include(treeOperations[1].data, { uid: uidOf('#beep', documents), parentUid: uidOf('truck', documents), }); });
it('parses a free-text description', function() { var docstring = multiline(function() { // hello }); var comment = subject.parseComment(docstring); assert.ok(comment); assert.equal(comment.description, 'hello'); });
it('parses a tag', function() { var docstring = multiline(function() { // @module }); var comment = subject.parseComment(docstring); assert.ok(comment); assert.equal(comment.tags.length, 1); });
it('parses inline "description"', function() { var tag = parse(function() {; // /** // * @param {String} name this is a description // */ }); assert.equal(tag.typeInfo.name, 'name'); assert.equal(tag.typeInfo.description, 'this is a description'); });
it('parses inline description without a name', function() { var tag = parse(function() {; // /** // * @return {true} If the record is valid. // */ }, { namedReturnTags: false }); assert.equal(tag.typeInfo.name, undefined); assert.equal(tag.typeInfo.description, 'If the record is valid.'); });
it('parses the name', function() { var tag = parse(function() {; // /** // * @return {String} foo // */ }); assert.equal(tag.typeInfo.name, 'foo'); assert.equal(tag.typeInfo.description, undefined); });
it('parses the name', function() { var tag = parse(function() {; // /** // * @property {String} foo // */ }); assert.equal(tag.typeInfo.name, 'foo'); assert.include(tag.typeInfo.type, { name: 'String' }); });
it('parses an optional property', function() { var tag = parse(function() {; // /** // * @property {String} [foo] // */ }); assert.equal(tag.typeInfo.isOptional, true); assert.equal(tag.typeInfo.name, 'foo'); });
it('parses the tag type', function() { var docstring = multiline(function() { // @module }); var tag = subject.parseTag(docstring.trim()); assert.ok(tag); assert.equal(tag.type, 'module') });
it('"{string[]}" => "Array.<string>"', function() { var docstring = multiline(function() { // {string[]} }).trim(); var types = subject.parseTagTypes(docstring); assert.ok(types); assert.equal(types.length, 1); assert.equal(types[0], 'Array.<string>'); });
it('understands a variable-bound function', function() { var nodeInfo = parseNode(function() {; // function me.something() // end }); assert.equal(nodeInfo.id, 'something') assert.equal(nodeInfo.ctx.type, 'function') assert.equal(nodeInfo.receiver, 'me') assert.equal(nodeInfo.indexer, '.') });
it('understands a function assigned to a table property', function() { var nodeInfo = parseNode(function() {; // me.something = function() // end }); assert.equal(nodeInfo.id, 'something') assert.equal(nodeInfo.ctx.type, 'function') assert.equal(nodeInfo.receiver, 'me') assert.equal(nodeInfo.indexer, '.') });
it('parses description without a name', function() { var tag = parse(function() {; // /** // * @return {String} // * Something. // */ }); assert.equal(tag.typeInfo.name, undefined); assert.equal(tag.typeInfo.description, 'Something.'); });
it('parses name and description', function() { var tag = parse(function() {; // /** // * @return {String} foo // * Something. // */ }); assert.equal(tag.typeInfo.name, 'foo'); assert.equal(tag.typeInfo.description, 'Something.'); });
it('works with "{string}"', function() { var docstring = multiline(function() { // {string} }).trim(); var types = subject.parseTagTypes(docstring); assert.ok(types); assert.equal(types.length, 1); assert.equal(types[0], 'string'); });
it('understands an assignment of a literal table property', function() { var nodeInfo = parseNode(function() {; // local t = {} // // t.foo = 'bar' }); assert.equal(nodeInfo.length, 2); assert.equal(nodeInfo[0].id, 't') assert.equal(nodeInfo[0].ctx.type, 'table') assert.equal(nodeInfo[1].id, 'foo') assert.equal(nodeInfo[1].ctx.type, 'literal') });
it('understands an inline table property', function() { var nodeInfo = parseNode(function() {; // local t = { // foo = 'bar' // } }); assert.equal(nodeInfo.length, 2); assert.equal(nodeInfo[0].id, 't') assert.equal(nodeInfo[0].ctx.type, 'table') assert.equal(nodeInfo[1].id, 'foo') assert.equal(nodeInfo[1].ctx.type, 'literal') });
it('parses a default value of "' + sample.defaultValue + '" => "' + sample.defaultValue + '"', function() { var docstring = '/** @property {Mixed} ' + sample.string + ' */' if (sample.error) { assert.throws(function() { parse(docstring); }, sample.error); } else { var tag = parse(docstring); assert.equal(tag.typeInfo.name, 'foo'); assert.equal(tag.typeInfo.defaultValue, sample.defaultValue); } });
it('understands an inline table function', function() { var nodeInfo = parseNode(function() {; // local t = { // foo = function() // end // } }); assert.equal(nodeInfo.length, 2); assert.equal(nodeInfo[0].id, 't') assert.equal(nodeInfo[0].ctx.type, 'table') assert.equal(nodeInfo[1].id, 'foo') assert.equal(nodeInfo[1].ctx.type, 'function') });
process: function(tag) { assert.doesNotThrow(function() { tag.setCustomAttribute('width', 240); }); done(); }
it('ignores multiple local variable declarations', function() { var nodeInfo = parseNode(function() {; // local foo, _ = 'bar' }); assert.equal(nodeInfo.id, undefined) });
it('understands a global variable declaration', function() { var nodeInfo = parseNode(function() {; // foo = 'bar' }); assert.equal(nodeInfo.id, 'foo') });
it('should leave undescribed properties of an object untouched', function() { const nextValue = subject({ name: 'foo', }, {}, useNext) assert.deepEqual(nextValue, { name: 'foo' }); })
it('does not cause double-escaping of text', function() { var text = subject({ text: 'hello [<world />](http://foobar)' }); assert.deepEqual(text.trim(), '<p>hello <a href="http://foobar"><world /></a></p>' ); });
it('whines if the node could not be found', function() { sinon.spy(NullLinter, 'logError'); const documents = [ b.document({ id: 'Klass', }) ]; subject({ id: 'foo', documents, linter: NullLinter, treeOperations: [ { type: 'CHANGE_NODE_PARENT', data: { uid: uidOf('Child', documents), parentUid: uidOf('Klass', documents), }, } ] }) assert.calledWith(NullLinter.logError, sinon.match({ message: sinon.match(/Node with UID ".+" specified as a child for node ".+" could not be found./) })) });
process: function(tag) { assert.throws(function() { tag.setCustomAttribute('foo', 'bar'); }, /Unrecognized custom attribute/); done(); }
it('reports the line of the comment in file', function() { sinon.spy(NullLinter, 'logRuleEntry') parse(function() {; // /** // * @property {(Object) -> Object} foo // */ }, {}, { commentNode: { loc: { start: { line: 3 } } } }); // assert.ok(tag.invalid) assert.calledWith(NullLinter.logRuleEntry, sinon.match({ rule: TypeExpressions, params: sinon.match({ typeString: '(Object) -> Object' }) })) })