2022-04-28 16:35:09 +00:00
|
|
|
open Jest
|
|
|
|
open Expect
|
|
|
|
|
2022-07-25 14:34:33 +00:00
|
|
|
module Bindings = Reducer_Bindings
|
2022-06-16 12:08:59 +00:00
|
|
|
module BindingsReplacer = Reducer_Expression_BindingsReplacer
|
2022-04-28 16:35:09 +00:00
|
|
|
module Expression = Reducer_Expression
|
2022-05-02 16:44:35 +00:00
|
|
|
module ExpressionWithContext = Reducer_ExpressionWithContext
|
2022-07-25 14:34:33 +00:00
|
|
|
module InternalExpressionValue = ReducerInterface.InternalExpressionValue
|
2022-05-02 16:44:35 +00:00
|
|
|
module Macro = Reducer_Expression_Macro
|
2022-07-25 14:34:33 +00:00
|
|
|
module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
|
2022-04-28 16:35:09 +00:00
|
|
|
module T = Reducer_Expression_T
|
|
|
|
|
|
|
|
let testMacro_ = (
|
|
|
|
tester,
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedCode: string,
|
|
|
|
) => {
|
2022-07-18 14:11:10 +00:00
|
|
|
let bindings = Bindings.fromArray(bindArray)
|
2022-09-07 18:45:19 +00:00
|
|
|
tester(expr->T.toString, () => {
|
|
|
|
let result = switch expr
|
|
|
|
->Reducer_Dispatch_BuiltInMacros.dispatchMacroCall(
|
2022-04-28 16:35:09 +00:00
|
|
|
bindings,
|
2022-07-25 14:34:33 +00:00
|
|
|
ProjectAccessorsT.identityAccessors,
|
|
|
|
Expression.reduceExpressionInProject,
|
2022-09-07 18:45:19 +00:00
|
|
|
) {
|
|
|
|
| v => Ok(v)
|
|
|
|
| exception Reducer_ErrorValue.ErrorException(e) => Error(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
result
|
2022-05-02 16:44:35 +00:00
|
|
|
->ExpressionWithContext.toStringResult
|
2022-04-28 16:35:09 +00:00
|
|
|
->expect
|
|
|
|
->toEqual(expectedCode)
|
2022-09-07 18:45:19 +00:00
|
|
|
})
|
2022-04-28 16:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let testMacroEval_ = (
|
|
|
|
tester,
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedValue: string,
|
|
|
|
) => {
|
2022-07-18 14:11:10 +00:00
|
|
|
let bindings = Bindings.fromArray(bindArray)
|
2022-04-28 16:35:09 +00:00
|
|
|
tester(expr->T.toString, () =>
|
|
|
|
expr
|
2022-06-16 12:08:59 +00:00
|
|
|
->Macro.doMacroCall(
|
|
|
|
bindings,
|
2022-07-25 14:34:33 +00:00
|
|
|
ProjectAccessorsT.identityAccessors,
|
|
|
|
Expression.reduceExpressionInProject,
|
2022-06-16 12:08:59 +00:00
|
|
|
)
|
2022-09-07 18:45:19 +00:00
|
|
|
->Ok
|
2022-06-16 12:08:59 +00:00
|
|
|
->InternalExpressionValue.toStringResult
|
2022-04-28 16:35:09 +00:00
|
|
|
->expect
|
|
|
|
->toEqual(expectedValue)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
let testMacro = (
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedExpr: string,
|
|
|
|
) => testMacro_(test, bindArray, expr, expectedExpr)
|
|
|
|
let testMacroEval = (
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedValue: string,
|
|
|
|
) => testMacroEval_(test, bindArray, expr, expectedValue)
|
|
|
|
|
|
|
|
module MySkip = {
|
|
|
|
let testMacro = (
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedExpr: string,
|
|
|
|
) => testMacro_(Skip.test, bindArray, expr, expectedExpr)
|
|
|
|
let testMacroEval = (
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedValue: string,
|
|
|
|
) => testMacroEval_(Skip.test, bindArray, expr, expectedValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
module MyOnly = {
|
|
|
|
let testMacro = (
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedExpr: string,
|
|
|
|
) => testMacro_(Only.test, bindArray, expr, expectedExpr)
|
|
|
|
let testMacroEval = (
|
2022-06-24 10:15:38 +00:00
|
|
|
bindArray: array<(string, InternalExpressionValue.t)>,
|
2022-04-28 16:35:09 +00:00
|
|
|
expr: T.expression,
|
|
|
|
expectedValue: string,
|
|
|
|
) => testMacroEval_(Only.test, bindArray, expr, expectedValue)
|
|
|
|
}
|