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

43 lines
1.6 KiB
Plaintext
Raw Normal View History

module Expression = Reducer_Expression
module ExpressionT = Reducer_Expression_T
2022-03-24 12:41:31 +00:00
open Jest
open Expect
let unwrapRecord = rValue =>
2022-04-27 20:24:06 +00:00
rValue->Belt.Result.flatMap(value =>
switch value {
| Reducer_T.IEvRecord(aRecord) => Ok(aRecord)
2022-09-26 00:44:08 +00:00
| _ => SqError.Message.RETodo("TODO: Internal bindings must be returned")->Error
2022-04-27 20:24:06 +00:00
}
)
let expectParseToBe = (code: string, answer: string) =>
Expression.BackCompatible.parse(code)->ExpressionT.toStringResult->expect->toBe(answer)
2022-04-17 17:24:39 +00:00
let expectEvalToBe = (code: string, answer: string) =>
2022-09-19 22:19:55 +00:00
Expression.BackCompatible.evaluateString(code)->Reducer_Value.toStringResult->expect->toBe(answer)
2022-04-15 06:56:48 +00:00
let expectEvalError = (code: string) =>
2022-08-19 18:56:45 +00:00
Expression.BackCompatible.evaluateString(code)
2022-09-19 19:10:09 +00:00
->Reducer_Value.toStringResult
2022-04-24 16:42:54 +00:00
->expect
->toMatch("Error\(")
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))
parser toFunction additive multiplicative compact whitespace pow relational equality boolean whitespace separator left associative operators expression not identifier function call array constructor string indexed values ident priority block outerBlock optional final expression statement separator outerBlock innerBlock better errors note xor white space and record unary minus inner/outer block statement lambda sort lambda is a value constructor lambdaCall ternary ternary basicValue cleanup quotes chained Functions dot operators unify unary operators unify unary operatos notes notes notes notes parser priorities set white space or newline defined allow newlines notes function call has become a post operator recordElement recursive index postOperatorToFunction better integer comments notes record priority comment atom finalComment generated parser type cast format initiate test file test initiated; todo nodeCall; nodeExpression callIdentifier recover extra initiate testing initial tests pass tests pass remove function node ternary test parse passed to tests pass notes sort toExpression format notes remove unused modules remove unnecessary nodeLambdaCall notes note fix construct array comment test todo elixir pipe fix toString notes initial to expression test value test parsing records records comments ternary ifthenelse inner block passed inner block lambda lambda new parser tested now test tricks ternary in expression to test lambda as argument to test lambda in structures Use peggy Parser expectEvalError macros tested remove mathjs parse reducer test comparison operator
2022-05-05 19:45:25 +00:00
let testEvalError = expr => test(expr, () => expectEvalError(expr))
2022-04-17 17:24:39 +00:00
let testEvalToBe = (expr, answer) => test(expr, () => expectEvalToBe(expr, answer))
let testDescriptionEvalToBe = (desc, expr, answer) => test(desc, () => expectEvalToBe(expr, 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 testEvalToBe = (expr, answer) => Skip.test(expr, () => expectEvalToBe(expr, 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 testEvalToBe = (expr, answer) => Only.test(expr, () => expectEvalToBe(expr, answer))
2022-04-17 17:24:39 +00:00
}