Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiriac committed Jan 7, 2017
1 parent ffbe9c3 commit 2c8e479
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
34 changes: 32 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,42 @@
* @authors https://github.com/glayzzle/docblock-parser/graphs/contributors
* @url http://glayzzle.com/docblock-parser
*/

// eslint-disable-next-line no-unused-vars
var should = require('should');
var DocBlockParser = require('../src/index');

describe('Test API', function () {
var doc = new DocBlockParser();
it('should parse something', function () {
it('should parse only summary', function () {
var ast = doc.parse('/** Hello world */');
console.log(ast);
ast.kind.should.be.exactly('doc');
ast.body.length.should.be.exactly(0);
ast.summary.should.be.exactly('Hello world');
});
it('should keep whitespaces', function () {
var ast = doc.parse([
'/**',
' * Hello world',
' * ',
' * Second line',
' * ',
' */'
].join('\n'));
ast.kind.should.be.exactly('doc');
ast.body.length.should.be.exactly(0);
ast.summary.should.be.exactly('Hello world\n\nSecond line\n');
});

it('test a simple annotation', function () {
var ast = doc.parse([
'/**',
' * Description',
' * @test',
' */'
].join('\n'));
ast.summary.should.be.exactly('Description');
ast.body.length.should.be.exactly(1);
ast.body[0].kind.should.be.exactly('block');
});
});
23 changes: 20 additions & 3 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ var should = require('should');
var DocBlockParser = require('../src/index');

describe('Test parser', function () {
var doc = new DocBlockParser();

it('extend grammar', function () {
var doc = new DocBlockParser({
var doc2 = new DocBlockParser({
foo: [],
return: [
null,
Expand All @@ -18,7 +20,22 @@ describe('Test parser', function () {
}
]
});
should.exist(doc.parser.grammar.foo);
doc.parser.grammar.return[1].property.should.be.exactly('bar');
should.exist(doc2.parser.grammar.foo);
doc2.parser.grammar.return[1].property.should.be.exactly('bar');
});

it('test number', function () {
var ast = doc.parse([
'/**',
' * Description',
' * @test 123 1.23',
' */'
].join('\n'));
ast.body[0].type.should.be.exactly('test');
ast.body[0].options.length.should.be.exactly(2);
ast.body[0].options[0].kind.should.be.exactly('number');
ast.body[0].options[0].value.should.be.exactly('123');
ast.body[0].options[1].kind.should.be.exactly('number');
ast.body[0].options[1].value.should.be.exactly('1.23');
});
});

0 comments on commit 2c8e479

Please sign in to comment.