Skip to content

Commit 993d9ef

Browse files
Handle tests that provide a full CQL <library> and a named <output> (e.g. the overload-matching test in cql-tests PR #61).
1 parent 60ba2f5 commit 993d9ef

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/commands/build-cql-command.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export class BuildCommand {
4343
testsName = r.testsName;
4444
}
4545

46+
// Library-style tests carry their own complete CQL library and are evaluated inline
47+
// (via the $cql `content` parameter), so they are not wrapped as a define here.
48+
if (r.library !== undefined) {
49+
continue;
50+
}
51+
4652
if (r.invalid !== 'semantic') {
4753
const defineVal = `define "${r.groupName}.${r.testName}": ${r.expression}`;
4854
const key = `${r.testsName}-${r.groupName}-${r.testName}`;

src/models/test-types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ export interface TestExpression {
33
invalid: 'false' | 'true' | 'semantic';
44
}
55

6+
export interface TestLibrary {
7+
text: string;
8+
invalid: 'false' | 'true' | 'semantic';
9+
}
10+
611
export interface TestOutput {
712
text: string;
13+
// For library-style tests, the name of the define whose result this output describes.
14+
name?: string;
815
type?:
916
| 'boolean'
1017
| 'code'
@@ -29,7 +36,9 @@ export interface Test {
2936
mode?: 'strict' | 'loose';
3037
ordered?: boolean;
3138
checkOrderedFunctions?: boolean;
32-
expression: string | TestExpression;
39+
// A test provides EITHER an expression OR a full CQL library (mutually exclusive; see testSchema.xsd).
40+
expression?: string | TestExpression;
41+
library?: string | TestLibrary;
3342
capability: CapabilityKV[];
3443
output?: string | TestOutput | string[] | TestOutput[];
3544
}
@@ -79,6 +88,9 @@ export interface InternalTestResult {
7988
testVersionTo?: string;
8089
invalid?: 'false' | 'true' | 'semantic' | 'undefined';
8190
expression: string;
91+
// For library-style tests: the full CQL library source that is evaluated inline.
92+
// (For these tests, `expression` holds the name of the define whose result is compared.)
93+
library?: string;
8294
capability?: CapabilityKV[];
8395
SkipMessage?: string;
8496
}

src/shared/results-shared.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class Result implements InternalTestResult {
1919
testVersionTo?: string;
2020
invalid: 'false' | 'true' | 'semantic' | 'undefined';
2121
expression: string;
22+
library?: string;
2223
capability: CapabilityKV[] = [];
2324

2425
constructor(testsName: string, groupName: string, test: Test) {
@@ -28,7 +29,23 @@ export class Result implements InternalTestResult {
2829
this.testVersion = test.version;
2930
this.testVersionTo = test.versionTo;
3031

31-
if (typeof test.expression !== 'string') {
32+
if (test.library !== undefined) {
33+
// Library-style test: the whole CQL library is evaluated inline. The value sent as
34+
// `expression` is the name of the define to evaluate, taken from the output's `name`
35+
// attribute (defaults to 'output').
36+
if (typeof test.library === 'string') {
37+
this.invalid = 'false';
38+
this.library = test.library;
39+
} else {
40+
this.invalid = test.library.invalid;
41+
this.library = test.library.text;
42+
}
43+
const out = test.output;
44+
this.expression =
45+
out !== undefined && typeof out !== 'string' && !Array.isArray(out) && out.name
46+
? out.name
47+
: 'output';
48+
} else if (typeof test.expression !== 'string') {
3249
if (test.expression === undefined) {
3350
this.invalid = 'undefined';
3451
this.expression = 'undefined';
@@ -117,6 +134,14 @@ export function generateParametersResource(
117134
},
118135
],
119136
};
137+
// Library-style tests: pass the full CQL library inline via the `content` parameter.
138+
// `expression` then names the define within that library to evaluate.
139+
if (result.library !== undefined) {
140+
data.parameter!.push({
141+
name: 'content',
142+
valueString: result.library,
143+
});
144+
}
120145
} else if (cqlEndpoint === '$evaluate') {
121146
data = {
122147
resourceType: 'Parameters',

0 commit comments

Comments
 (0)