Skip to content

Commit 3ca8278

Browse files
committed
Clean up ExprFunction tests
1 parent 9c6e0f9 commit 3ca8278

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2234
-2483
lines changed

lang/src/org/partiql/lang/eval/Exceptions.kt

+11-8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ internal fun errNoContext(message: String, errorCode: ErrorCode, internal: Boole
5252
internal fun err(message: String, errorCode: ErrorCode, errorContext: PropertyValueMap?, internal: Boolean): Nothing =
5353
throw EvaluationException(message, errorCode, errorContext, internal = internal)
5454

55+
internal fun expectedArgTypeErrorMsg (types: List<ExprValueType>) : String = when (types.size) {
56+
0 -> throw IllegalStateException("Should have at least one expected argument type. ")
57+
1 -> types[0].toString()
58+
else -> {
59+
val window = types.size - 1
60+
val (most, last) = types.windowed(window, window, true)
61+
most.joinToString(", ") + ", or ${last.first()}"
62+
}
63+
}
64+
5565
/** Throw an [ErrorCode.EVALUATOR_INCORRECT_TYPE_OF_ARGUMENTS_TO_FUNC_CALL] error */
5666
internal fun errInvalidArgumentType(
5767
signature: FunctionSignature,
@@ -62,14 +72,7 @@ internal fun errInvalidArgumentType(
6272
): Nothing {
6373
val arity = signature.arity
6474

65-
val expectedTypeMsg = when(expectedTypes.size) {
66-
1 -> expectedTypes[0]
67-
else -> {
68-
val window = expectedTypes.size - 1
69-
val (most, last) = expectedTypes.windowed(window, window, true)
70-
most.joinToString(", ") + ", or ${last.first()}"
71-
}
72-
}
75+
val expectedTypeMsg = expectedArgTypeErrorMsg(expectedTypes)
7376

7477
val errorContext = propertyValueMapOf(
7578
Property.FUNCTION_NAME to signature.name,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.partiql.lang.eval.builtins
2+
3+
import com.amazon.ion.Timestamp
4+
import org.partiql.lang.ION
5+
import org.partiql.lang.eval.Bindings
6+
import org.partiql.lang.eval.EvaluationSession
7+
import org.partiql.lang.eval.ExprValue
8+
import org.partiql.lang.eval.ExprValueFactory
9+
import org.partiql.lang.util.newFromIonText
10+
11+
/**
12+
* Internal function used by ExprFunctionTest to test invalid argument type.
13+
*/
14+
internal val invalidArgTypeChecker = InvalidArgTypeChecker()
15+
internal fun checkInvalidArgType(funcName: String, syntaxSuffix: String = "(", args: List<Argument>) =
16+
invalidArgTypeChecker.checkInvalidArgType(funcName, syntaxSuffix, args)
17+
18+
/**
19+
* Internal function used by ExprFunctionTest to test invalid arity.
20+
*/
21+
internal val invalidArityChecker = InvalidArityChecker()
22+
internal fun checkInvalidArity(funcName: String, minArity: Int, maxArity: Int) =
23+
invalidArityChecker.checkInvalidArity(funcName, minArity, maxArity)
24+
25+
private val valueFactory = ExprValueFactory.standard(ION)
26+
27+
private fun String.toExprValue(): ExprValue = valueFactory.newFromIonText(this)
28+
29+
private fun Map<String, String>.toBindings(): Bindings<ExprValue> = Bindings.ofMap(mapValues { it.value.toExprValue() })
30+
31+
/**
32+
* Internal function used by ExprFunctionTest to build EvaluationSession.
33+
*/
34+
internal fun Map<String, String>.toSession() = EvaluationSession.build { globals([email protected]()) }
35+
36+
/**
37+
* Internal function used by ExprFunctionTest to build EvaluationSession with now.
38+
*/
39+
internal fun buildSessionWithNow(numMillis: Long, localOffset: Int) =
40+
EvaluationSession.build { now(Timestamp.forMillis(numMillis, localOffset)) }
41+
42+
/**
43+
* Used by ExprFunctionTest to represent a test case.
44+
*/
45+
data class ExprFunctionTestCase(
46+
val source: String,
47+
val expected: String,
48+
val session: EvaluationSession = EvaluationSession.standard()
49+
)

lang/test/org/partiql/lang/eval/builtins/CharLengthEvaluationTest.kt

-19
This file was deleted.

lang/test/org/partiql/lang/eval/builtins/ConcatEvaluationTest.kt

-52
This file was deleted.

lang/test/org/partiql/lang/eval/builtins/DateAddEvaluationTest.kt

-83
This file was deleted.

0 commit comments

Comments
 (0)