2022-03-29 09:09:59 +00:00
|
|
|
module Expression = Reducer.Expression
|
|
|
|
module ExpressionValue = ReducerInterface.ExpressionValue
|
2022-04-27 20:00:42 +00:00
|
|
|
module ErrorValue = Reducer_ErrorValue
|
2022-03-24 12:41:31 +00:00
|
|
|
|
|
|
|
open Jest
|
|
|
|
open Expect
|
|
|
|
|
2022-04-27 20:00:42 +00:00
|
|
|
let unwrapRecord = rValue =>
|
2022-04-27 20:24:06 +00:00
|
|
|
rValue->Belt.Result.flatMap(value =>
|
|
|
|
switch value {
|
|
|
|
| ExpressionValue.EvRecord(aRecord) => Ok(aRecord)
|
|
|
|
| _ => ErrorValue.RETodo("TODO: External bindings must be returned")->Error
|
|
|
|
}
|
|
|
|
)
|
2022-04-27 20:00:42 +00:00
|
|
|
|
2022-03-24 12:41:31 +00:00
|
|
|
let expectParseToBe = (expr: string, answer: string) =>
|
2022-03-30 10:53:36 +00:00
|
|
|
Reducer.parse(expr)->Expression.toStringResult->expect->toBe(answer)
|
2022-03-24 12:41:31 +00:00
|
|
|
|
2022-04-17 18:07:21 +00:00
|
|
|
let expectParseOuterToBe = (expr: string, answer: string) =>
|
|
|
|
Reducer.parseOuter(expr)->Expression.toStringResult->expect->toBe(answer)
|
|
|
|
|
2022-04-17 17:24:39 +00:00
|
|
|
let expectParsePartialToBe = (expr: string, answer: string) =>
|
2022-04-17 18:07:21 +00:00
|
|
|
Reducer.parsePartial(expr)->Expression.toStringResult->expect->toBe(answer)
|
2022-04-17 17:24:39 +00:00
|
|
|
|
2022-03-24 12:41:31 +00:00
|
|
|
let expectEvalToBe = (expr: string, answer: string) =>
|
2022-04-11 01:18:38 +00:00
|
|
|
Reducer.evaluate(expr)->ExpressionValue.toStringResult->expect->toBe(answer)
|
2022-04-15 06:56:48 +00:00
|
|
|
|
|
|
|
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
|
2022-04-27 20:24:06 +00:00
|
|
|
Reducer.evaluateUsingOptions(
|
|
|
|
expr,
|
|
|
|
~externalBindings=Some(bindings),
|
|
|
|
~isPartial=None,
|
|
|
|
~environment=None,
|
|
|
|
)
|
2022-04-24 16:42:54 +00:00
|
|
|
->ExpressionValue.toStringResult
|
|
|
|
->expect
|
|
|
|
->toBe(answer)
|
2022-04-17 17:24:39 +00:00
|
|
|
|
2022-04-17 18:32:47 +00:00
|
|
|
let expectEvalPartialBindingsToBe = (
|
|
|
|
expr: string,
|
|
|
|
bindings: Reducer.externalBindings,
|
|
|
|
answer: string,
|
|
|
|
) =>
|
2022-04-27 20:24:06 +00:00
|
|
|
Reducer.evaluateUsingOptions(
|
|
|
|
expr,
|
|
|
|
~externalBindings=Some(bindings),
|
|
|
|
~isPartial=Some(true),
|
|
|
|
~environment=None,
|
|
|
|
)
|
2022-04-27 20:00:42 +00:00
|
|
|
->unwrapRecord
|
2022-04-17 18:32:47 +00:00
|
|
|
->ExpressionValue.toStringResultRecord
|
|
|
|
->expect
|
|
|
|
->toBe(answer)
|
2022-04-17 18:07:21 +00:00
|
|
|
|
2022-04-17 17:24:39 +00:00
|
|
|
let testParseToBe = (expr, answer) => test(expr, () => expectParseToBe(expr, answer))
|
2022-04-17 18:07:21 +00:00
|
|
|
let testParseOuterToBe = (expr, answer) => test(expr, () => expectParseOuterToBe(expr, answer))
|
|
|
|
let testParsePartialToBe = (expr, answer) => test(expr, () => expectParsePartialToBe(expr, answer))
|
2022-04-17 17:24:39 +00:00
|
|
|
let testDescriptionParseToBe = (desc, expr, answer) =>
|
|
|
|
test(desc, () => expectParseToBe(expr, answer))
|
|
|
|
|
|
|
|
let testEvalToBe = (expr, answer) => test(expr, () => expectEvalToBe(expr, answer))
|
|
|
|
let testDescriptionEvalToBe = (desc, expr, answer) => test(desc, () => expectEvalToBe(expr, answer))
|
|
|
|
let testEvalBindingsToBe = (expr, bindingsList, answer) =>
|
|
|
|
test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
|
2022-04-17 18:07:21 +00:00
|
|
|
let testEvalPartialBindingsToBe = (expr, bindingsList, answer) =>
|
|
|
|
test(expr, () => expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
|
|
|
|
|
2022-04-17 17:24:39 +00:00
|
|
|
module MySkip = {
|
2022-04-17 18:32:47 +00:00
|
|
|
let testParseToBe = (expr, answer) => Skip.test(expr, () => expectParseToBe(expr, answer))
|
|
|
|
let testParseOuterToBe = (expr, answer) =>
|
|
|
|
Skip.test(expr, () => expectParseOuterToBe(expr, answer))
|
|
|
|
let testParsePartialToBe = (expr, answer) =>
|
|
|
|
Skip.test(expr, () => expectParsePartialToBe(expr, answer))
|
2022-04-17 18:07:21 +00:00
|
|
|
let testEvalToBe = (expr, answer) => Skip.test(expr, () => expectEvalToBe(expr, answer))
|
2022-04-17 17:24:39 +00:00
|
|
|
let testEvalBindingsToBe = (expr, bindingsList, answer) =>
|
|
|
|
Skip.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
|
2022-04-17 18:07:21 +00:00
|
|
|
let testEvalPartialBindingsToBe = (expr, bindingsList, answer) =>
|
2022-04-17 18:32:47 +00:00
|
|
|
Skip.test(expr, () =>
|
|
|
|
expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)
|
|
|
|
)
|
2022-04-17 17:24:39 +00:00
|
|
|
}
|
|
|
|
module MyOnly = {
|
2022-04-17 18:32:47 +00:00
|
|
|
let testParseToBe = (expr, answer) => Only.test(expr, () => expectParseToBe(expr, answer))
|
|
|
|
let testParseOuterToBe = (expr, answer) =>
|
|
|
|
Only.test(expr, () => expectParseOuterToBe(expr, answer))
|
|
|
|
let testParsePartialToBe = (expr, answer) =>
|
|
|
|
Only.test(expr, () => expectParsePartialToBe(expr, answer))
|
2022-04-17 18:07:21 +00:00
|
|
|
let testEvalToBe = (expr, answer) => Only.test(expr, () => expectEvalToBe(expr, answer))
|
2022-04-17 17:24:39 +00:00
|
|
|
let testEvalBindingsToBe = (expr, bindingsList, answer) =>
|
|
|
|
Only.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
|
2022-04-17 18:07:21 +00:00
|
|
|
let testEvalPartialBindingsToBe = (expr, bindingsList, answer) =>
|
2022-04-17 18:32:47 +00:00
|
|
|
Only.test(expr, () =>
|
|
|
|
expectEvalPartialBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer)
|
|
|
|
)
|
2022-04-17 17:24:39 +00:00
|
|
|
}
|