squiggle/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res

41 lines
1.7 KiB
Plaintext
Raw Normal View History

2022-03-29 09:09:59 +00:00
module Expression = Reducer.Expression
module ExpressionValue = ReducerInterface.ExpressionValue
2022-03-24 12:41:31 +00:00
open Jest
open Expect
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 17:24:39 +00:00
let expectParsePartialToBe = (expr: string, answer: string) =>
Reducer.parse(expr)->Expression.toStringResult->expect->toBe(answer)
2022-03-24 12:41:31 +00:00
let expectEvalToBe = (expr: string, answer: string) =>
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) =>
Reducer.evaluateWBindings(expr, bindings)->ExpressionValue.toStringResult->expect->toBe(answer)
2022-04-17 17:24:39 +00:00
let testParseToBe = (expr, answer) => test(expr, () => expectParseToBe(expr, answer))
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))
module MySkip = {
let testEvalBindingsToBe = (expr, bindingsList, answer) =>
Skip.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
let testEvalToBe = (expr, answer) => Skip.test(expr, () => expectEvalToBe(expr, answer))
}
module MyOnly = {
let testEvalBindingsToBe = (expr, bindingsList, answer) =>
Only.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
let testEvalToBe = (expr, answer) => Only.test(expr, () => expectEvalToBe(expr, answer))
}