Skip to content

Commit

Permalink
MAT-7998 update error message when definition name is key word
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu committed Dec 23, 2024
1 parent c9ebb35 commit 56e1969
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
130 changes: 130 additions & 0 deletions src/util/CustomeErrorConverter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,127 @@
const keyWords: string[] = [
"after",
"aggregate",
"all",
"and",
"as",
"asc",
"ascending",
"before",
"between",
"by",
"called",
"case",
"cast",
"code",
"Code",
"codesystem",
"codesystems",
"collapse",
"concept",
"Concept",
"contains",
"context",
"convert",
"date",
"day",
"days",
"default",
"define",
"desc",
"descending",
"difference",
"display",
"distinct",
"div",
"duration",
"during",
"else",
"end",
"ends",
"except",
"exists",
"expand",
"false",
"flatten",
"fluent",
"from",
"function",
"hour",
"hours",
"if",
"implies",
"in",
"include",
"includes",
"included in",
"intersect",
"Interval",
"is",
"let",
"library",
"List",
"maximum",
"meets",
"millisecond",
"milliseconds",
"minimum",
"minute",
"minutes",
"mod",
"month",
"months",
"not",
"null",
"occurs",
"of",
"on or",
"or",
"or after",
"or before",
"or less",
"or more",
"or on",
"overlaps",
"parameter",
"per",
"point",
"predecessor",
"private",
"properly",
"public",
"return",
"same",
"second",
"seconds",
"singleton",
"start",
"starting",
"starts",
"sort",
"successor",
"such that",
"then",
"time",
"timezoneoffset",
"to",
"true",
"Tuple",
"union",
"using",
"valueset",
"version",
"week",
"weeks",
"where",
"when",
"width",
"with",
"within",
"without",
"xor",
"year",
"years",
];
const convertCustomError = (errorMessage: string): string => {
let convertedMsg: string = errorMessage;
switch (errorMessage) {
Expand All @@ -6,6 +130,12 @@ const convertCustomError = (errorMessage: string): string => {
break;
}
default: {
const findKeyword = errorMessage
?.replace(/'/g, "")
.replace("no viable alternative at input define ", "");
if (findKeyword && keyWords.find((kword) => findKeyword === kword)) {
convertedMsg = "Definition names must not be a reserved word.";
}
break;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/CqlAntlr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
relatedContextRetrieve,
aggregateQuery,
cqlDefineWithNoName,
cqlDefineWithKeyWord,
} from "./testCql";
import { CqlAntlr } from "../src";
import CqlResult from "../src/dto/CqlResult";
Expand Down Expand Up @@ -187,4 +188,13 @@ describe("test antlr", () => {
"Definition is missing a name."
);
});

it("test define with key words", (): void => {
const cqlAntlr = new CqlAntlr(cqlDefineWithKeyWord);
const cqlResult: CqlResult = cqlAntlr.parse();
expect(cqlResult.errors.length).toEqual(1);
expect(cqlResult.errors[0].message).toEqual(
"Definition names must not be a reserved word."
);
});
});
5 changes: 5 additions & 0 deletions test/testCql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ const cqlDefineWithNoName = `
define :
true
`;
const cqlDefineWithKeyWord = `
define on or:
true
`;
export {
simpleDefinitionCql,
fhirTestCql,
Expand All @@ -237,4 +241,5 @@ export {
relatedContextRetrieve,
aggregateQuery,
cqlDefineWithNoName,
cqlDefineWithKeyWord,
};

0 comments on commit 56e1969

Please sign in to comment.