Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions tests/cql/CqlOverloadMatching.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://hl7.org/fhirpath/tests" xsi:schemaLocation="http://hl7.org/fhirpath/tests ../testSchema.xsd"
name="OverloadMatching" reference="https://cql.hl7.org/03-developersguide.html#conversion-precedence">
<group name="OverloadMatching">
<test name="ExactIntegerOverThanConversion">
<!-- An exact type match takes precedence over an implicit Integer->Decimal conversion: https://cql.hl7.org/03-developersguide.html#conversion-precedence -->
<library>
library ExactIntegerOverThanConversion version '1.0.0'

define function A(foo Integer): 'IntegerOverload'
define function A(foo Decimal): 'DecimalOverload'

define output: A(1)
</library>
<output name="output">'IntegerOverload'</output>
</test>
<test name="ImplicitIntegerToDecimal">
<!-- With no exact match, the Integer argument is implicitly converted to Decimal: https://cql.hl7.org/03-developersguide.html#conversion-precedence -->
<library>
library ImplicitIntegerToDecimal version '1.0.0'

define function A(foo Decimal): 'DecimalOverload'

define output: A(1)
</library>
<output name="output">'DecimalOverload'</output>
</test>
<test name="ExactLongOverload">
<capability code="system.long" />
<!-- A Long argument exactly matches the Long overload rather than converting to Decimal: https://cql.hl7.org/03-developersguide.html#conversion-precedence -->
<library>
library ExactLongOverload version '1.0.0'

define function A(foo Integer): 'IntegerOverload'
define function A(foo Long): 'LongOverload'

define output: A(1L)
</library>
<output name="output">'LongOverload'</output>
</test>
<test name="ImplicitIntegerToLong">
<capability code="system.long" />
<!-- With no exact match, the Integer argument is implicitly converted to Long: https://cql.hl7.org/03-developersguide.html#conversion-precedence -->
<library>
library ImplicitIntegerToLong version '1.0.0'

define function A(foo Long): 'LongOverload'

define output: A(1)
</library>
<output name="output">'LongOverload'</output>
</test>
<test name="ExactDecimalOverQuantity">
<!-- An exact Decimal match takes precedence over an implicit Decimal->Quantity conversion: https://cql.hl7.org/03-developersguide.html#conversion-precedence -->
<library>
library ExactDecimalOverQuantity version '1.0.0'

define function A(foo Decimal): 'DecimalOverload'
define function A(foo Quantity): 'QuantityOverload'

define output: A(1.0)
</library>
<output name="output">'DecimalOverload'</output>
</test>
<test name="AmbiguousOverload">
<capability code="system.long" />
<!-- The Integer argument can convert to both Long and Decimal with equal precedence, so the call is ambiguous and fails to translate (semantic error): https://cql.hl7.org/03-developersguide.html#conversion-precedence -->
<library invalid="semantic">
library AmbiguousOverload version '1.0.0'

define function A(foo Long): 'LongOverload'
define function A(foo Decimal): 'DecimalOverload'

define output: A(1)
</library>
</test>
</group>
</tests>
45 changes: 42 additions & 3 deletions tests/testSchema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,27 @@
</xs:annotation>
</xs:element>

<xs:element name="expression" type="Expression">
<xs:choice>
<xs:annotation>
<xs:documentation>The expression to be tested.</xs:documentation>
<xs:documentation>
The item under test: either a single CQL expression, or a complete CQL library.
Exactly one must be provided. Use 'library' instead of 'expression' when the test
requires library-level declarations (e.g. function overloads, parameters, includes,
or multiple named defines); the expected results are then matched to the library's
defines via the 'name' attribute on 'output'.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="expression" type="Expression">
<xs:annotation>
<xs:documentation>The expression to be tested.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="library" type="Library">
<xs:annotation>
<xs:documentation>The complete CQL library to be tested.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:choice>
<xs:element name="output" type="Output" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>The expected output of the test.</xs:documentation>
Expand Down Expand Up @@ -199,6 +215,24 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="Library">
<xs:annotation>
<xs:documentation>
A complete CQL library provided as the body of the test. The content is the CQL source
text (including the 'library' declaration and any defines/functions). Results are matched
to individual defines via the 'name' attribute on the test's 'output' element(s).
</xs:documentation>
</xs:annotation>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="invalid" type="InvalidType">
<xs:annotation>
<xs:documentation>Indicates whether the library is expected to translate/evaluate successfully, or to produce a syntax, semantic, or runtime error.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="Output">
<xs:simpleContent>
<xs:extension base="xs:string">
Expand All @@ -207,6 +241,11 @@
<xs:documentation>The type of the expected output. If output type is not present, the content of the output is the string representation of a literal (e.g. 10.0)</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="name" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>For library-style tests, the name of the define whose expected result this output describes (corresponds to a 'define' statement in the library). Omitted for single-expression tests.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down
Loading