Skip to content

Commit

Permalink
Run tests one at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
jmandel committed Oct 12, 2023
1 parent 805d53a commit 0716c7a
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 149 deletions.
10 changes: 2 additions & 8 deletions tests/content/fn_exists.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
"resource": "Patient",
"select": [
{
"column": [
{ "path": "id" },
{ "path": "name.exists()", "alias": "has_name" }
]
"column": [{ "path": "id" }, { "path": "name.exists()", "alias": "has_name" }]
}
]
},
Expand All @@ -52,10 +49,7 @@
"resource": "Patient",
"select": [
{
"column": [
{ "path": "id" },
{ "path": "name.given.exists()", "alias": "has_name" }
]
"column": [{ "path": "id" }, { "path": "name.given.exists()", "alias": "has_name" }]
}
]
},
Expand Down
12 changes: 3 additions & 9 deletions tests/content/fn_extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"resourceType": "Patient",
"id": "pt1",
"meta": {
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
]
"profile": ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"]
},
"extension": [
{
Expand Down Expand Up @@ -44,9 +42,7 @@
"resourceType": "Patient",
"id": "pt2",
"meta": {
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
]
"profile": ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"]
},
"extension": [
{
Expand Down Expand Up @@ -83,9 +79,7 @@
"resourceType": "Patient",
"id": "pt3",
"meta": {
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
]
"profile": ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"]
},
"extension": []
}
Expand Down
15 changes: 3 additions & 12 deletions tests/content/fn_join.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
"resource": "Patient",
"select": [
{
"column": [
{ "path": "id" },
{ "path": "name.given.join(',')", "alias": "given" }
]
"column": [{ "path": "id" }, { "path": "name.given.join(',')", "alias": "given" }]
}
]
},
Expand All @@ -34,10 +31,7 @@
"resource": "Patient",
"select": [
{
"column": [
{ "path": "id" },
{ "path": "name.given.join('')", "alias": "given" }
]
"column": [{ "path": "id" }, { "path": "name.given.join('')", "alias": "given" }]
}
]
},
Expand All @@ -49,10 +43,7 @@
"resource": "Patient",
"select": [
{
"column": [
{ "path": "id" },
{ "path": "name.given.join()", "alias": "given" }
]
"column": [{ "path": "id" }, { "path": "name.given.join()", "alias": "given" }]
}
]
},
Expand Down
4 changes: 1 addition & 3 deletions tests/content/fn_rkeys.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"title": "get resource key",
"view": {
"resource": "Observation",
"select": [
{ "column": [{ "path": "getResourceKey()", "alias": "id" }] }
]
"select": [{ "column": [{ "path": "getResourceKey()", "alias": "id" }] }]
},
"expectCount": 1
},
Expand Down
4 changes: 1 addition & 3 deletions tests/content/path_traversal.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
"resource": "Observation",
"select": [
{
"column": [
{ "path": "value.ofType(string)", "alias": "valueString" }
]
"column": [{ "path": "value.ofType(string)", "alias": "valueString" }]
}
]
},
Expand Down
28 changes: 13 additions & 15 deletions tests/content/union.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
],
"contact": [
{
"name": {"family": "f2"}
"name": { "family": "f2" }
}
]
}
],
"tests": [
{
{
"title": "Union of names",
"view": {
"resource": "Patient",
Expand All @@ -27,44 +27,42 @@
"union": [
{
"forEach": "name",
"column": [{"path": "family"}]
"column": [{ "path": "family" }]
},
{
"forEach": "contact.name",
"column": [{"path": "family"}]
"column": [{ "path": "family" }]
}
]
}
]
},
"expect": [
{"family": "f1"},
{"family": "f2"}
]
},{
"expect": [{ "family": "f1" }, { "family": "f2" }]
},
{
"title": "Union of names with top-level context",
"view": {
"resource": "Patient",
"select": [
{
"column": [{"path": "'x'", "alias": "common"}],
"column": [{ "path": "'x'", "alias": "common" }],
"union": [
{
"forEach": "name",
"column": [{"path": "family"}]
"column": [{ "path": "family" }]
},
{
"forEach": "contact.name",
"column": [{"path": "family"}]
"column": [{ "path": "family" }]
}
]
}
]
},
"expect": [
{"common":"x", "family": "f1"},
{"common":"x", "family": "f2"}
{ "common": "x", "family": "f1" },
{ "common": "x", "family": "f2" }
]
}
}
]
}
8 changes: 2 additions & 6 deletions tests/content/where.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@
"view": {
"resource": "Patient",
"select": [{ "column": [{ "path": "id" }] }],
"where": [
{ "path": "name.where(use = 'official' and family = 'f1').exists()" }
]
"where": [{ "path": "name.where(use = 'official' and family = 'f1').exists()" }]
},
"expect": [{ "id": "p1" }]
},
Expand All @@ -108,9 +106,7 @@
"view": {
"resource": "Patient",
"select": [{ "column": [{ "path": "id" }] }],
"where": [
{ "path": "name.where(use = 'official' or family = 'f2').exists()" }
]
"where": [{ "path": "name.where(use = 'official' or family = 'f2').exists()" }]
},
"expect": [{ "id": "p1" }, { "id": "p2" }]
},
Expand Down
51 changes: 19 additions & 32 deletions tests/generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,24 @@ function validatePathToSubset(path) {
function validateChildren(node) {
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i]
if (nodeTypeAllowList.indexOf(child.type) == -1)
return `Unsupported node type: ${child.type}`
if (
child.type == 'AdditiveExpression' &&
child.terminalNodeText.indexOf('&') > -1
)
if (nodeTypeAllowList.indexOf(child.type) == -1) return `Unsupported node type: ${child.type}`
if (child.type == 'AdditiveExpression' && child.terminalNodeText.indexOf('&') > -1)
return 'Unsupported use of &'
if (
child.type == 'MultiplicativeExpression' &&
(child.terminalNodeText.indexOf('mod') > -1 ||
child.terminalNodeText.indexOf('div') > -1)
(child.terminalNodeText.indexOf('mod') > -1 || child.terminalNodeText.indexOf('div') > -1)
)
return `Unsupported use of ${
child.terminalNodeText.indexOf('mod') > -1 ? 'mod' : 'div'
}`
return `Unsupported use of ${child.terminalNodeText.indexOf('mod') > -1 ? 'mod' : 'div'}`
if (
child.type == 'EqualityExpression' &&
(child.terminalNodeText.indexOf('~') > -1 ||
child.terminalNodeText.indexOf('!~') > -1)
(child.terminalNodeText.indexOf('~') > -1 || child.terminalNodeText.indexOf('!~') > -1)
)
return 'Unsupported use of ~'
if (
child.type == 'OrExpression' &&
child.terminalNodeText.indexOf('xor') > -1
)
if (child.type == 'OrExpression' && child.terminalNodeText.indexOf('xor') > -1)
return 'Unsupported use of xor'
if (child.type == 'Functn') {
const fnIdentifier = child.children.find((c) => c.type == 'Identifier')
if (fnAllowList.indexOf(fnIdentifier.text) == -1)
return `Unsupported function: ${fnIdentifier.text}`
if (fnAllowList.indexOf(fnIdentifier.text) == -1) return `Unsupported function: ${fnIdentifier.text}`
}
if (child.children) {
const validationError = validateChildren(child)
Expand Down Expand Up @@ -120,32 +108,31 @@ await Promise.all(
if (path.extname(file) !== '.json') return
let testData
let validate
let testResults
testData = JSON.parse(await fs.promises.readFile(CONTENT + file))
validate = testData.allowExtendedFhirpath ? validateFull : validateSubset
testResults = await runTests(testData)
allResults.push({ testResults, testData, file, validate })
})
allResults.push({ testData, file, validate })
}),
)

allResults.forEach(({ testData, testResults, file, validate }) => {
allResults.forEach(({ testData, file, validate }) => {
describe(`${file}`, () => {
test(`Validate Schema for ${file}`, () => {
expect(validate(testData)).toBe(true)
})

testResults.tests.forEach((t) => {
test(t.title, () => {
if (!t.result.passed) {
testData.tests.forEach((tDef, i) => {
test(tDef.title, async () => {
let testOutput = (await runTests({ ...testData, tests: [tDef] })).tests[0]
if (!testOutput.result.passed) {
throw new Error(
`Expected: ${JSON.stringify(
t.expect,
`Expected: ${JSON.stringify(testOutput.expect, null, 2)}, Observed: ${JSON.stringify(
testOutput.result.observed,
null,
2
)}, Observed: ${JSON.stringify(t.result.observed, null, 2)}`
2,
)}`,
)
}
expect(t.result.passed).toBe(true)
expect(testOutput.result.passed).toBe(true)
})
})
})
Expand Down
7 changes: 3 additions & 4 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"type": "module",
"scripts": {
"fmt": "npx prettier content --write"
"fmt": "prettier --write *.js *.json content/*.json reference-implementation/processor.js "
},
"author": "",
"license": "ISC",
Expand All @@ -15,11 +15,10 @@
"prettier": "^3.0.3"
},
"prettier": {
"trailingComma": "es5",
"printWidth": 110,
"tabWidth": 2,
"semi": false,
"singleQuote": true
},
"devDependencies": {
}
"devDependencies": {}
}
Loading

0 comments on commit 0716c7a

Please sign in to comment.