Skip to content

Commit

Permalink
Caret rule on ValueSet should have at most one concept
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-thompson committed Aug 4, 2023
1 parent 1b55608 commit 5e5889c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/import/FSHImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,15 @@ export class FSHImporter extends FSHVisitor {
}
} else if (ctx.codeCaretValueRule()) {
const rule = this.visitCodeCaretValueRule(ctx.codeCaretValueRule(), true);
// the rule needs to have a caretPath and a value.
// the rule needs to have a caretPath, a value, and a pathArray with one element.
// various syntax errors may lead to some of these values being missing.
// the appropriate error has already been logged by FSHErrorHandler.
if (rule.caretPath != null && rule.value != null) {
if (rule.pathArray.length > 1) {
logger.error(
'Only one concept may be listed before a caret rule on a ValueSet.',
rule.sourceInfo
);
} else if (rule.caretPath != null && rule.value != null) {
return rule;
}
} else if (ctx.insertRule()) {
Expand Down
27 changes: 27 additions & 0 deletions test/import/FSHImporter.ValueSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,33 @@ describe('FSHImporter', () => {
]);
expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
});

it('should log an error when a caret rule has more than one concept', () => {
// ValueSet: ZooVS
// * ZOO#hippo "Hippopotamus"
// * ZOO#rhino "Rhinoceros"
// * ZOO#hippo ZOO#rhino ^designation.value = "hipopótamo"
const input = leftAlign(`
ValueSet: ZooVS
* ZOO#hippo "Hippopotamus"
* ZOO#rhino "Rhinoceros"
* ZOO#hippo ZOO#rhino ^designation.value = "hipopótamo"
`);
const result = importSingleText(input, 'Zoo.fsh');
expect(result.valueSets.size).toBe(1);
const valueSet = result.valueSets.get('ZooVS');
expect(valueSet.rules.length).toBe(1);
assertValueSetConceptComponent(valueSet.rules[0], 'ZOO', undefined, [
new FshCode('hippo', 'ZOO', 'Hippopotamus')
.withLocation([3, 3, 3, 26])
.withFile('Zoo.fsh'),
new FshCode('rhino', 'ZOO', 'Rhinoceros').withLocation([4, 3, 4, 24]).withFile('Zoo.fsh')
]);
expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
expect(loggerSpy.getLastMessage('error')).toMatch(
/Only one concept may be listed before a caret rule on a ValueSet\..*File: Zoo\.fsh.*Line: 5\D*/s
);
});
});

describe('#insertRule', () => {
Expand Down

0 comments on commit 5e5889c

Please sign in to comment.