cqframework / cqframework/cql-tests
Substring tests with similar intent but different expected output
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 7
- Forks
- 8
- Avg merge
- 12d 5h
- Merged PRs (30d)
- 2
Description
There are two tests in CqlStringOperatorsTest.xml that seemingly test the same concept (Substring of a string, starting at string.length) but have different results, empty string vs null.
<test name="SubstringAB2" version="1.0">
<capability code="string-operators" />
<expression>Substring('ab', 2)</expression>
<output>null</output>
</test>
<test name="SubstringEmptyAnd0" version="1.0">
<capability code="string-operators" />
<expression>Substring('', 0)</expression>
<output>''</output>
</test>
The most relevant sections of the spec I could find are in the Developer's Guide, String Operators: https://cql.hl7.org/R2/03-developersguide.html#string-operators
The second argument is the starting index of the substring to be returned, and the third argument is the length of the substring to be returned. If the length is greater than the number of characters present in the string from the starting index on, the result includes only the remaining characters. If the starting index is less than 0, or greater than the length of the string, the result is null. The third argument is optional; if it is not provided, the substring is taken from the starting index to the end of the string.
and the CQL Reference: https://cql.hl7.org/09-b-cqlreference.html#substring
If stringToSub or startIndex is null, or startIndex is out of range, the result is null.
(note "out of range" is not defined more specifically anywhere that I saw)
In both these cases, the starting index is not less than zero, nor is it greater than the length of the string. So by that reading I think SubstringEmptyAnd0 is correct and the expected output for both should be empty string. That test was added more recently, with some discussion, here: https://github.com/cqframework/cql-tests/pull/55
However, I'll also note that in FHIRpath, the substring operator is more clearly defined on this case:
https://hl7.org/fhirpath/en/#substringstart--integer--length--integer--string
If start lies outside, or equal to, the length of the string, the function returns empty ({ }). If there are less remaining characters in the string than indicated by length, the function returns just the remaining characters.
with the specific example
''.substring(0) // { } (start position is outside the string)
(CQL is not FHIRPath but as I understand it there's a strong push to keep them aligned)
I don't have a strong sense either way, other than I think these 2 test cases should have the same expected output.
Submitting this as an issue instead of a PR to invite discussion
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the two cases in CqlStringOperatorsTest.xml, then read the cited String Operators section of the Developer's Guide and the CQL Reference. Compare their handling of a start index equal to string length, including the linked discussion in pull request 55. Done means the interpretation is resolved and the two tests have consistent expected outputs.
Written by the indexing model from the issue text.
Assessment
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100