db050668d1
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
53 lines
2.3 KiB
Plaintext
53 lines
2.3 KiB
Plaintext
module ExpressionT = Reducer_Expression_T
|
|
module ExpressionValue = ReducerInterface.ExpressionValue
|
|
module ErrorValue = Reducer_ErrorValue
|
|
|
|
open Jest
|
|
open Expect
|
|
|
|
let unwrapRecord = rValue =>
|
|
rValue->Belt.Result.flatMap(value =>
|
|
switch value {
|
|
| ExpressionValue.EvRecord(aRecord) => Ok(aRecord)
|
|
| _ => ErrorValue.RETodo("TODO: External bindings must be returned")->Error
|
|
}
|
|
)
|
|
|
|
let expectParseToBe = (expr: string, answer: string) =>
|
|
Reducer.parse(expr)->ExpressionT.toStringResult->expect->toBe(answer)
|
|
|
|
let expectEvalToBe = (expr: string, answer: string) =>
|
|
Reducer.evaluate(expr)->ExpressionValue.toStringResult->expect->toBe(answer)
|
|
|
|
let expectEvalError = (expr: string) =>
|
|
Reducer.evaluate(expr)->ExpressionValue.toStringResult->expect->toMatch("Error\(")
|
|
|
|
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
|
|
Reducer.evaluateUsingOptions(expr, ~externalBindings=Some(bindings), ~environment=None)
|
|
->ExpressionValue.toStringResult
|
|
->expect
|
|
->toBe(answer)
|
|
|
|
let testParseToBe = (expr, answer) => test(expr, () => expectParseToBe(expr, answer))
|
|
let testDescriptionParseToBe = (desc, expr, answer) =>
|
|
test(desc, () => expectParseToBe(expr, answer))
|
|
|
|
let testEvalError = expr => test(expr, () => expectEvalError(expr))
|
|
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 testParseToBe = (expr, answer) => Skip.test(expr, () => expectParseToBe(expr, answer))
|
|
let testEvalToBe = (expr, answer) => Skip.test(expr, () => expectEvalToBe(expr, answer))
|
|
let testEvalBindingsToBe = (expr, bindingsList, answer) =>
|
|
Skip.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
|
|
}
|
|
module MyOnly = {
|
|
let testParseToBe = (expr, answer) => Only.test(expr, () => expectParseToBe(expr, answer))
|
|
let testEvalToBe = (expr, answer) => Only.test(expr, () => expectEvalToBe(expr, answer))
|
|
let testEvalBindingsToBe = (expr, bindingsList, answer) =>
|
|
Only.test(expr, () => expectEvalBindingsToBe(expr, bindingsList->Js.Dict.fromList, answer))
|
|
}
|