-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...gine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/FunctionRefEvaluatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.opencds.cqf.cql.engine.elm.executing; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import javax.xml.namespace.QName; | ||
import org.hl7.elm.r1.*; | ||
import org.junit.jupiter.api.Test; | ||
import org.opencds.cqf.cql.engine.exception.CqlException; | ||
import org.opencds.cqf.cql.engine.execution.Environment; | ||
import org.opencds.cqf.cql.engine.execution.State; | ||
|
||
class FunctionRefEvaluatorTest { | ||
@Test | ||
void pickFunctionDef() { | ||
var env = new Environment(null); | ||
var state = new State(env); | ||
state.init(new Library().withIdentifier(new VersionedIdentifier().withId("lib"))); | ||
|
||
var cqlException = assertThrows( | ||
CqlException.class, | ||
() -> FunctionRefEvaluator.pickFunctionDef(state, "func", List.of(1, 2, 3), List.of(), List.of())); | ||
assertEquals( | ||
"Could not resolve call to operator 'func(java.lang.Integer, java.lang.Integer, java.lang.Integer)' in library 'lib'.", | ||
cqlException.getMessage()); | ||
} | ||
|
||
@Test | ||
void functionDefOperandsSignatureEqual() { | ||
var functionDefWithOneOperand = new FunctionDef().withOperand(new OperandDef()); | ||
List<TypeSpecifier> signatureWithTwoOperands = List.of(new NamedTypeSpecifier(), new NamedTypeSpecifier()); | ||
|
||
assertFalse(FunctionRefEvaluator.functionDefOperandsSignatureEqual( | ||
functionDefWithOneOperand, signatureWithTwoOperands)); | ||
} | ||
|
||
@Test | ||
void operandDefTypeSpecifierEqual() { | ||
var integerTypeName = new QName("urn:hl7-org:elm-types:r1", "Integer"); | ||
var integerNamedTypeSpecifier = new NamedTypeSpecifier().withName(integerTypeName); | ||
var listTypeSpecifier = new ListTypeSpecifier().withElementType(integerNamedTypeSpecifier); | ||
|
||
var listOperandDef = new OperandDef().withOperandTypeSpecifier(listTypeSpecifier); | ||
var integerOperandDef = new OperandDef().withOperandType(integerTypeName); | ||
|
||
assertTrue(FunctionRefEvaluator.operandDefTypeSpecifierEqual(listOperandDef, listTypeSpecifier)); | ||
assertTrue(FunctionRefEvaluator.operandDefTypeSpecifierEqual(integerOperandDef, integerNamedTypeSpecifier)); | ||
assertFalse(FunctionRefEvaluator.operandDefTypeSpecifierEqual(integerOperandDef, null)); | ||
} | ||
|
||
@Test | ||
void typesToString() { | ||
var env = new Environment(null); | ||
var state = new State(env); | ||
|
||
var actual = FunctionRefEvaluator.typesToString(state, List.of("a", "b", "c")); | ||
assertEquals("java.lang.String, java.lang.String, java.lang.String", actual); | ||
|
||
actual = FunctionRefEvaluator.typesToString(state, Arrays.asList(1, 2, null)); | ||
assertEquals("java.lang.Integer, java.lang.Integer, null", actual); | ||
|
||
actual = FunctionRefEvaluator.typesToString(state, null); | ||
assertEquals("", actual); | ||
} | ||
} |