Skip to content

Commit

Permalink
allow javadoc comments before and after enum values (#15202)
Browse files Browse the repository at this point in the history
Fix #15185
  • Loading branch information
nomuna authored Jun 6, 2021
1 parent 6e63904 commit 0e4a6e0
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 1 deletion.
8 changes: 7 additions & 1 deletion jdl/parsing/jdl-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,21 @@ module.exports = class JDLParser extends CstParser {

enumProp() {
this.RULE('enumProp', () => {
this.CONSUME(LexerTokens.NAME, { LABEL: 'enumPropKey' });
this.OPTION(() => {
this.CONSUME(LexerTokens.JAVADOC);
});
this.CONSUME(LexerTokens.NAME, { LABEL: 'enumPropKey' });
this.OPTION1(() => {
this.CONSUME(LexerTokens.LPAREN);
this.OR([
{ ALT: () => this.CONSUME2(LexerTokens.STRING, { LABEL: 'enumPropValueWithQuotes' }) },
{ ALT: () => this.CONSUME3(LexerTokens.NAME, { LABEL: 'enumPropValue' }) },
]);
this.CONSUME(LexerTokens.RPAREN);
});
this.OPTION2(() => {
this.CONSUME1(LexerTokens.JAVADOC);
});
});
}

Expand Down
140 changes: 140 additions & 0 deletions test/jdl/grammar/grammar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,146 @@ entity A {
});
});
});

context('without custom values but with comments', () => {
let parsedEnum;

before(() => {
const content = parseFromContent(
`enum MyEnum {
/** some comment */FRANCE /** some comment */,
/** some comment */ ITALY /** some comment */,
ENGLAND /** some comment */,
ICELAND/** some comment */,
/** some comment */IRELAND,
/** some comment */ CANADA
}
`
);
parsedEnum = content.enums[0];
});

it('should parse it', () => {
expect(parsedEnum).to.deep.equal({
name: 'MyEnum',
values: [
{
key: 'FRANCE',
},
{
key: 'ITALY',
},
{
key: 'ENGLAND',
},
{
key: 'ICELAND',
},
{
key: 'IRELAND',
},
{
key: 'CANADA',
},
],
});
});
});

context('with custom values containing spaces and with comments', () => {
let parsedEnum;

before(() => {
const content = parseFromContent(
`enum MyEnum {
/** some comment */FRANCE ("cheese and wine country") /** some comment */,
/** some comment */ ITALY /** some comment */,
ENGLAND ("not a tea country") /** some comment */,
ICELAND/** some comment */,
/** some comment */IRELAND,
/** some comment */ CANADA
}
`
);
parsedEnum = content.enums[0];
});

it('should parse it', () => {
expect(parsedEnum).to.deep.equal({
name: 'MyEnum',
values: [
{
key: 'FRANCE',
value: 'cheese and wine country',
},
{
key: 'ITALY',
},
{
key: 'ENGLAND',
value: 'not a tea country',
},
{
key: 'ICELAND',
},
{
key: 'IRELAND',
},
{
key: 'CANADA',
},
],
});
});
});

context('with custom values containing underscores and with comments', () => {
let parsedEnum;

before(() => {
const content = parseFromContent(
`enum MyEnum {
/** some comment */FRANCE ("cheese_and_wine_country") /** some comment */,
/** some comment */ ITALY /** some comment */,
ENGLAND ("not_a_tea_country") /** some comment */,
ICELAND/** some comment */,
/** some comment */IRELAND,
/** some comment */ CANADA
}
`
);
parsedEnum = content.enums[0];
});

it('should parse it', () => {
expect(parsedEnum).to.deep.equal({
name: 'MyEnum',
values: [
{
key: 'FRANCE',
value: 'cheese_and_wine_country',
},
{
key: 'ITALY',
},
{
key: 'ENGLAND',
value: 'not_a_tea_country',
},
{
key: 'ICELAND',
},
{
key: 'IRELAND',
},
{
key: 'CANADA',
},
],
});
});
});

context('without values', () => {
context('without spaces', () => {
let parsedEnum;
Expand Down

0 comments on commit 0e4a6e0

Please sign in to comment.