Skip to content

Commit

Permalink
Add data tests #24
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Jul 8, 2023
1 parent 1d44fa1 commit 4d390b3
Show file tree
Hide file tree
Showing 47 changed files with 70,268 additions and 566 deletions.
68 changes: 68 additions & 0 deletions tests/cases/3.2_paths.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,73 @@
tests:
- 'group: Paths with choice types':
- desc: 'Observation.value with an R5 FHIR model'
expression: 'Observation.value'
result: ["high"]
model: 'r5'

- desc: 'Observation.value with an R4 FHIR model'
expression: 'Observation.value'
result: ["high"]
model: 'r4'

- desc: 'Observation.value with an STU3 FHIR model'
expression: 'Observation.value'
result: ["high"]
model: 'stu3'

- desc: 'Observation.value with an DSTU2 FHIR model'
expression: 'Observation.value'
result: ["high"]
model: 'dstu2'

- desc: 'Observation.value without a model'
expression: 'Observation.value'
result: []

- desc: 'Observation.value contained in another resource (1)'
expression: 'Observation.contained[0].value'
model: 'r4'
result: ['medium']

- desc: 'Observation.value contained in another resource (2)'
expression: 'Observation.contained.value'
model: 'r4'
result: ['medium', 'low']

- desc: 'Getting choice type fields via children()'
expression: 'Observation.children().value'
model: 'r4'
result: ['medium', 'low']

- desc: 'Getting choice type fields via children() (2)'
expression: 'Observation.children().children().value'
model: 'r4'
result: ['zero']

- desc: 'Getting choice type fields via descendants()'
expression: 'Observation.descendants().value'
model: 'r4'
result: ['medium', 'low', 'zero', 'Red', 'Blue', 'Green']

- desc: 'Getting choice type fields via descendants() and where()'
expression: "Observation.descendants().where(resourceType = 'Observation').value"
model: 'r4'
result: ['medium', 'low', 'zero']

- desc: "QR with where()"
expression: "contained.where(resourceType = 'QuestionnaireResponse').item.where(linkId = '1').answer.value"
model: 'r4'
result: ['Red']

- desc: "QR with descendants() and where() (1)"
expression: "contained.where(resourceType = 'QuestionnaireResponse').descendants().where(linkId = '1').answer.value"
model: 'r4'
result: ['Red']

- desc: "QR with descendants() and where() (2)"
expression: "contained.where(resourceType = 'QuestionnaireResponse').descendants().where(linkId = '1.0').answer.value"
model: 'r4'
result: ['Green']

- desc: "QR with descendants() and where() (3)"
expression: "contained.where(resourceType = 'QuestionnaireResponse').descendants().where(linkId = '1.1').answer.value"
Expand Down
40 changes: 40 additions & 0 deletions tests/cases/4.1_literals.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
tests:
- expression: '{}'
result: []
- expression: "'a\\\\b\\'\\\"\\`\\r\\n\\t\\u0065'" # double escape for YAML
result: ["a\\b'\"`\r\n\te"]
- expression: "\"a\\\\b\\'\\\"\\`\\r\\n\\t\\u0065\"" # using " to wrap a string is not allowed by grammar
error: true
- expression: "`a\\\\b\\'\\\"\\`\\r\\n\\t\\u0065`" # using ` to wrap a string is not allowed by grammar
error: true
- expression: "2 'mo'"
result: ["2 'mo'"]
- expression: "2 years"
result: ["2 years"]
- expression: "(2 years).value" # test of internal structure, not FHIRPath
result: [2]
- expression: "@2019"
result: ["2019"]
- expression: "@2019-02-03T01:00Z = @2019-02-02T21:00-04:00"
result: [true]
- expression: "@2019-02-03T02:00Z = @2019-02-02T21:00-04:00"
result: [false]
- expression: '-7'
result: [-7]
- expression: '-7.3'
result: [-7.3]
- expression: '+7'
result: [+7]
- expression: '(-7).combine(3)'
result: [-7, 3]
- expression: '-7.combine(3)' # same as next case
error: true
- expression: '-((7).combine(3))'
error: true # per Bryn
- expression: '-true'
error: true
- expression: "-'zzz'"
error: true

subject:
prop: val
40 changes: 34 additions & 6 deletions tests/cases/5.1_existence.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@ tests:
expression: Functions.attrempty.not()
result: []

- desc: '** not empty, non-boolean coll with not() is empty'
- desc: '** multi-valued coll with not() is invalid'
expression: Functions.attrdouble.not()
result: []

- desc: '** multi-valued boolean coll with not() is empty'
expression: Functions.attrdouble.not()
result: []
error: true

- desc: '** not nothing is empty coll'
expression: Functions.nothing.not()
Expand Down Expand Up @@ -117,6 +113,10 @@ tests:
expression: Functions.coll1.coll2.attr.all($this = 5)
result: [false]

- desc: '** the ability to use $index in the expression'
expression: (0|1|2|3).all($this = $index)
result: [true]


- desc: '5.1.5. allTrue() : boolean'
# Takes a collection of boolean values and returns
Expand Down Expand Up @@ -326,6 +326,25 @@ tests:
expression: Functions.coll1[0].coll2.attr.distinct()
result: [1, 2, 3]

- desc: '** should not depend on the order of properties in an object'
expression: Functions.objects.distinct()
result:
- prop1: 1
prop2: 2
- prop1: 3
prop2: 4
- prop1: 5
prop2: 6

- desc: '** should use year-to-month conversion factor (https://hl7.org/fhirpath/#equals)'
expression: (1 year).combine(12 months).distinct()
result:
- 1 year

- desc: '** should compare quantities for equality (https://hl7.org/fhirpath/#equals)'
expression: (3 'min').combine(180 seconds).distinct()
result:
- 3 'min'

- desc: '5.1.13. count() : integer'
# Returns a collection with a single value which is
Expand Down Expand Up @@ -410,4 +429,13 @@ subject:
c:
e: 6
d: 5
objects:
- prop1: 1
prop2: 2
- prop1: 3
prop2: 4
- prop2: 2
prop1: 1
- prop1: 5
prop2: 6

2 changes: 2 additions & 0 deletions tests/cases/5.2.3_repeat.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
tests:
- expression: Questionnaire.repeat(item).linkId
result: ["1", "2", "1.1", "2.1", "1.1.1", "2.1.2", "1.1.1.1", "1.1.1.2", "1.1.1.1.1", "1.1.1.1.2"]
- expression: Questionnaire.combine(Questionnaire).repeat(item).linkId
result: ["1", "2", "1.1", "2.1", "1.1.1", "2.1.2", "1.1.1.1", "1.1.1.2", "1.1.1.1.1", "1.1.1.1.2"]
subject:
resourceType: Questionnaire
id: '3141'
Expand Down
29 changes: 23 additions & 6 deletions tests/cases/5.2_filtering_and_projection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ tests:
expression: Functions.coll1.coll2.attr.where($this = 0)
result: []

- desc: '** the ability to use $index in the expression'
expression: Functions.coll1.coll2.attr.where($index > 2)
result: [4, 5]

# If the input collection is emtpy ({ }), the result is empty.

- desc: '** filter empty coll'
Expand Down Expand Up @@ -42,6 +46,9 @@ tests:
expression: Functions.attrempty.select(nothing)
result: []

- desc: '** the ability to use $index in the expression'
expression: Functions.coll1.coll2.select(attr + $index)
result: [1, 3, 5, 7, 9]

- desc: '5.2.3. repeat(projection: expression) : collection'
# A version of select that will repeat the projection and add it to the output collection, as long as the projection yields new items (as determined by the equals (=) operator).
Expand All @@ -59,10 +66,20 @@ tests:
# Questionnaire.descendants().select(group | question)
# which would find any descendants called group or question, not just the ones nested inside other group or question elements.
- desc: '* traverse tree'
- desc: '** find all true values in nested coll'
- desc: 'TODO FIX INF LOOP'
# expression: Functions.coll1.colltrue.repeat(true)
# result: [true, true, true]
- desc: '** should not result in an infinite loop 1'
expression: Functions.coll1.colltrue.repeat(true)
result: [true]
- desc: '** should not result in an infinite loop 2'
expression: (1 | 2).repeat('item')
result: ['item']
- desc: '** should use year-to-month conversion factor (https://hl7.org/fhirpath/#equals)'
expression: (1 year).combine(12 months).repeat($this)
result:
- 1 year
- desc: '** should compare quantities for equality (https://hl7.org/fhirpath/#equals)'
expression: (3 'min').combine(180 seconds).repeat($this)
result:
- 3 'min'
- desc: '** find all attrs'
expression: Functions.repeat(repeatingAttr).count()
result: [2]
Expand All @@ -73,7 +90,7 @@ tests:

- desc: '** find all true values in nested coll'
expression: Functions.coll1.colltrue.repeat(attr)
result: [true, true, true]
result: [true]

- desc: '** find non-exists value'
expression: Functions.coll1.repeat(nothing)
Expand All @@ -93,7 +110,7 @@ tests:
result: [1]
- desc: '** decimal'
expression: heteroattr.ofType(decimal)
result: [1, 1.01]
result: [1.01]
- desc: '** boolean'
expression: heteroattr.ofType(boolean)
result: [true, false]
Expand Down
32 changes: 32 additions & 0 deletions tests/cases/5.3_subsetting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ tests:
expression: Functions.coll1.coll2.attr.take(5)
result: [1, 2, 3, 4, 5]

- desc: '5.3.8. intersect(other: collection) : collection'
- desc: '** should not depend on the order of properties in an object'
expression: Functions.objects.group1.intersect(Functions.objects.group2)
result:
- prop1: 1
prop2: 2

- desc: '** should use year-to-month conversion factor (https://hl7.org/fhirpath/#equals)'
expression: (1 year).combine(12 months).intersect(12 months)
result:
- 1 year

- desc: '** should compare quantities for equality (https://hl7.org/fhirpath/#equals)'
expression: (3 'min').combine(180 seconds).intersect(180 seconds)
result:
- 3 'min'

subject:
resourceType: Functions
attrempty: []
Expand Down Expand Up @@ -216,3 +233,18 @@ subject:
- attr: '@2015-02-04T14:34:28Z'
- attr: '@T14:34:28+09:00'
- attr: 4 days
objects:
group1:
- prop1: 1
prop2: 2
- prop1: 1
prop2: 2
- prop1: 3
prop2: 4
group2:
- prop2: 2
prop1: 1
- prop2: 2
prop1: 1
- prop1: 5
prop2: 6
67 changes: 67 additions & 0 deletions tests/cases/5.4_combining.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,64 @@
tests:
- desc: '5. Functions'
- desc: '5.4. Combining'
- desc: '5.4.1. | (union collections)'
# Merge the two collections into a single collection, eliminating any duplicate values (using equals (=)) to determine equality). Unioning an empty collection to a non-empty collection will return the non-empty collection with duplicates eliminated. There is no expectation of order in the resulting collection.

- desc: '** Unioning empty coll with non-exists coll is empty coll'
expression: Functions.coll1.nothing | Functions.attrempty
result: []

- desc: '** Unioning empty coll with non-distinct coll is coll without duplicates'
expression: Functions.attrempty | Functions.coll1.colltrue.attr
result: [true]

- desc: '** Unioning colls'
expression: Functions.attrdouble | Functions.coll1.colltrue.attr
result: [1, 2, true]

- desc: '** Unioning colls 2'
expression: Functions.attrdouble | Functions.coll1.coll2.attr
result: [1, 2, 3, 4, 5]

- desc: '** should use year-to-month conversion factor (https://hl7.org/fhirpath/#equals)'
expression: (1 year | 12 months)
result:
- 1 year

- desc: '** should compare quantities for equality (https://hl7.org/fhirpath/#equals)'
expression: (3 'min' | 180 seconds)
result:
- 3 'min'

- desc: '** should not depend on the order of properties in an object'
expression: Functions.objects.group1 | Functions.objects.group2
result:
- prop1: 1
prop2: 2
- prop1: 3
prop2: 4
- prop1: 5
prop2: 6

- desc: '5.4.2. combine(other : collection) : collection'
# Merge the input and other collections into a single collection without eliminating duplicate values. Combining an empty collection with a non-empty collection will return the non-empty collection. There is no expectation of order in the resulting collection.

- desc: '** Combine empty coll with non-exists coll is empty coll'
expression: Functions.attrempty.combine(Functions.nothing)
result: []

- desc: '** Combine empty coll with non-empty coll'
expression: Functions.attrempty.combine(Functions.coll1.colltrue.attr)
result: [true, true, true]

- desc: '** Combine colls'
expression: Functions.attrdouble.combine(Functions.coll1.colltrue.attr)
result: [1, 2, true, true, true]

- desc: '** Combine colls 2'
expression: Functions.attrdouble.combine(Functions.coll1.coll2.attr)
result: [1, 2, 1, 2, 3, 4, 5]

subject:
resourceType: Functions
attrempty: []
Expand Down Expand Up @@ -48,3 +104,14 @@ subject:
- attr: '@2015-02-04T14:34:28Z'
- attr: '@T14:34:28+09:00'
- attr: 4 days
objects:
group1:
- prop1: 1
prop2: 2
- prop1: 3
prop2: 4
group2:
- prop2: 2
prop1: 1
- prop1: 5
prop2: 6

0 comments on commit 4d390b3

Please sign in to comment.