Skip to content

Commit

Permalink
improve tests & fix array parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiriac committed Jan 8, 2017
1 parent 9861453 commit ecbe333
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ Parser.prototype.parseStatement = function () {
}
return {
kind: 'word',
value: this.lexer.text
value: this.lexer.backup.text
};
}

Expand Down Expand Up @@ -630,16 +630,6 @@ Parser.prototype.readArray = function (endChar) {
var item = this.parseTopStatement();
if (item !== null) { // ignore
item = this.getJsonValue(item);
if (this.token === '=>') {
this.token = this.lexer.lex(); // eat
item = {
kind: 'key',
name: item,
value: this.getJsonValue(
this.parseTopStatement()
)
};
}
result.push(item);
if (this.token !== ',') {
break;
Expand Down
29 changes: 29 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,33 @@ describe('Test parser', function () {
ast.body[2].kind.should.be.exactly('object');
should.equal(ast.body[2].value, null);
});

it('test getJsonValue', function () {
var ast = doc.parse([
'/**',
' * @object { foo: { bar: false }, "key": [1, 2, 3] }',
' */'
].join('\n'));
ast.body[0].kind.should.be.exactly('object');
ast.body[0].value.should.be.eql({foo: {bar: false}, key: [1, 2, 3]});
});

it('test readArray', function () {
var ast = doc.parse([
'/**',
' * @array [foo => bar, 1, 2, array]',
' */'
].join('\n'));
ast.body[0].kind.should.be.exactly('array');
ast.body[0].value.should.be.eql([
{
kind: 'key',
name: 'foo',
value: 'bar'
},
1,
2,
'array'
]);
});
});

0 comments on commit ecbe333

Please sign in to comment.