Skip to content

Commit

Permalink
Add enum comments test cases
Browse files Browse the repository at this point in the history
Fix #14869
  • Loading branch information
swarajsaaj committed Jun 18, 2021
1 parent f15d526 commit 4876866
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 6 deletions.
1 change: 1 addition & 0 deletions jdl/parsing/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function getCst(input, startRule = 'prog') {
if (extraSyntaxErrors.length > 0) {
throwSyntaxError(extraSyntaxErrors);
}

return cst;
}

Expand Down
38 changes: 38 additions & 0 deletions test/jdl/converters/JDLToJSON/jdl-to-json-field-converter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,44 @@ describe('JDLToJSONFieldConverter', () => {
});
});
});
context('with field types being enums with comments', () => {
let convertedField;

before(() => {
const jdlObject = new JDLObject();
const entityA = new JDLEntity({
name: 'A',
comment: 'The best entity',
});
const enumType = new JDLEnum({
comment: 'enum comment',
name: 'CustomEnum',
values: ['AA', 'AB'].map(value => ({ key: value, comment: 'some comment' })),
});
const enumField = new JDLField({
name: 'enumField',
type: 'CustomEnum',
});
jdlObject.addEnum(enumType);
entityA.addField(enumField);
jdlObject.addEntity(entityA);
const returnedMap = convert(jdlObject);
convertedField = returnedMap.get('A')[0];
});

it('should convert them', () => {
expect(convertedField).to.deep.equal({
fieldName: 'enumField',
fieldType: 'CustomEnum',
fieldTypeJavadoc: 'enum comment',
fieldValuesJavadocs: {
AA: 'some comment',
AB: 'some comment',
},
fieldValues: 'AA,AB',
});
});
});
context('with comments', () => {
let convertedField;

Expand Down
21 changes: 21 additions & 0 deletions test/jdl/models/jdl-enum.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ describe('JDLEnum', () => {
expect(result).to.equal('A (aaaa),B');
});
});
describe('getValueJavadocs', () => {
let result;

before(() => {
const jdlEnum = new JDLEnum({
name: 'Toto',
values: [
{ key: 'A', value: 'aaaa', comment: 'first comment' },
{ key: 'B', comment: 'second comment' },
],
});
result = jdlEnum.getValueJavadocs();
});

it('should return the value javadocs object', () => {
expect(result).to.deep.equal({
A: 'first comment',
B: 'second comment',
});
});
});
describe('toString', () => {
context('with simple enum values', () => {
let values = [];
Expand Down
50 changes: 44 additions & 6 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('JHipster Utils', () => {

before(() => {
const clientRootFolder = 'root';
const field = { enumName: 'fieldName', fieldType: 'BigLetters', fieldValues: 'AAA, BBB' };
const field = { enumName: 'fieldName', fieldType: 'BigLetters', fieldValues: 'AAA, BBB', fieldTypeJavadoc: 'enum comment' };
enumInfo = utils.getEnumInfo(field, clientRootFolder);
});

Expand All @@ -67,6 +67,9 @@ describe('JHipster Utils', () => {
it('returns the enums values', () => {
assert.deepStrictEqual(enumInfo.enums, ['AAA', 'BBB']);
});
it('returns the enums comment', () => {
assert.deepStrictEqual(enumInfo.javadoc, '/**\n * enum comment\n */');
});
});
describe("when the enums don't have custom values", () => {
let enumInfo;
Expand All @@ -84,8 +87,8 @@ describe('JHipster Utils', () => {
});
it('returns the enums values', () => {
assert.deepStrictEqual(enumInfo.enumValues, [
{ name: 'AAA', value: 'AAA' },
{ name: 'BBB', value: 'BBB' },
{ name: 'AAA', value: 'AAA', comment: undefined },
{ name: 'BBB', value: 'BBB', comment: undefined },
]);
});
});
Expand All @@ -108,8 +111,9 @@ describe('JHipster Utils', () => {
{
name: 'AAA',
value: 'aaa',
comment: undefined,
},
{ name: 'BBB', value: 'BBB' },
{ name: 'BBB', value: 'BBB', comment: undefined },
]);
});
});
Expand All @@ -133,8 +137,9 @@ describe('JHipster Utils', () => {
{
name: 'AAA',
value: 'aaa',
comment: undefined,
},
{ name: 'BBB', value: 'bbb' },
{ name: 'BBB', value: 'bbb', comment: undefined },
]);
});
});
Expand All @@ -157,8 +162,41 @@ describe('JHipster Utils', () => {
{
name: 'AAA',
value: 'aaa',
comment: undefined,
},
{ name: 'BBB', value: 'bbb and b', comment: undefined },
]);
});
});
describe('with comments over them', () => {
let enumInfo;

before(() => {
const clientRootFolder = 'root';
const field = {
enumName: 'fieldName',
fieldValues: 'AAA(aaa), BBB(bbb and b)',
fieldValuesJavadocs: {
AAA: 'first comment',
BBB: 'second comment',
},
};
enumInfo = utils.getEnumInfo(field, clientRootFolder);
});

it('returns whether there are custom enums', () => {
assert.strictEqual(enumInfo.withoutCustomValues, false);
assert.strictEqual(enumInfo.withSomeCustomValues, false);
assert.strictEqual(enumInfo.withCustomValues, true);
});
it('returns the enums values', () => {
assert.deepStrictEqual(enumInfo.enumValues, [
{
name: 'AAA',
value: 'aaa',
comment: '/**\n * first comment\n */',
},
{ name: 'BBB', value: 'bbb and b' },
{ name: 'BBB', value: 'bbb and b', comment: '/**\n * second comment\n */' },
]);
});
});
Expand Down

0 comments on commit 4876866

Please sign in to comment.