reformat
This commit is contained in:
parent
05e8540b31
commit
a5bb390370
|
@ -1,18 +1,13 @@
|
|||
open Jest
|
||||
open Reducer_TestHelpers
|
||||
|
||||
let testParseToBe = (expr, answer) => test(expr, () => expectParseToBe(expr, answer))
|
||||
|
||||
let testParseToBe = (expr, answer) =>
|
||||
test(expr, () => expectParseToBe(expr, answer))
|
||||
let testDescParseToBe = (desc, expr, answer) => test(desc, () => expectParseToBe(expr, answer))
|
||||
|
||||
let testDescParseToBe = (desc, expr, answer) =>
|
||||
test(desc, () => expectParseToBe(expr, answer))
|
||||
let testEvalToBe = (expr, answer) => test(expr, () => expectEvalToBe(expr, answer))
|
||||
|
||||
let testEvalToBe = (expr, answer) =>
|
||||
test(expr, () => expectEvalToBe(expr, answer))
|
||||
|
||||
let testDescEvalToBe = (desc, expr, answer) =>
|
||||
test(desc, () => expectEvalToBe(expr, answer))
|
||||
let testDescEvalToBe = (desc, expr, answer) => test(desc, () => expectEvalToBe(expr, answer))
|
||||
|
||||
describe("reducer using mathjs parse", () => {
|
||||
// Test the MathJs parser compatibility
|
||||
|
@ -40,11 +35,12 @@ describe("reducer using mathjs parse", () => {
|
|||
testDescParseToBe("index", "([0,1,2])[1]", "Ok((:$atIndex (0 1 2) (1)))")
|
||||
})
|
||||
describe("records", () => {
|
||||
testDescParseToBe("define",
|
||||
"{a: 1, b: 2}", "Ok((:$constructRecord (('a' 1) ('b' 2))))")
|
||||
testDescParseToBe("use",
|
||||
"{a: 1, b: 2}.a",
|
||||
"Ok((:$atIndex (:$constructRecord (('a' 1) ('b' 2))) ('a')))")
|
||||
testDescParseToBe("define", "{a: 1, b: 2}", "Ok((:$constructRecord (('a' 1) ('b' 2))))")
|
||||
testDescParseToBe(
|
||||
"use",
|
||||
"{a: 1, b: 2}.a",
|
||||
"Ok((:$atIndex (:$constructRecord (('a' 1) ('b' 2))) ('a')))",
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -68,8 +64,7 @@ describe("eval", () => {
|
|||
testEvalToBe("[1, 2, 3]", "Ok([1, 2, 3])")
|
||||
testEvalToBe("['hello', 'world']", "Ok(['hello', 'world'])")
|
||||
testEvalToBe("([0,1,2])[1]", "Ok(1)")
|
||||
testDescEvalToBe("index not found",
|
||||
"([0,1,2])[10]", "Error(Array index not found: 10)")
|
||||
testDescEvalToBe("index not found", "([0,1,2])[10]", "Error(Array index not found: 10)")
|
||||
})
|
||||
describe("records", () => {
|
||||
test("define", () => expectEvalToBe("{a: 1, b: 2}", "Ok({a: 1, b: 2})"))
|
||||
|
@ -79,8 +74,10 @@ describe("eval", () => {
|
|||
})
|
||||
|
||||
describe("test exceptions", () => {
|
||||
testDescEvalToBe("javascript exception",
|
||||
"jsraise('div by 0')", "Error(JS Exception: Error: 'div by 0')")
|
||||
testDescEvalToBe("rescript exception",
|
||||
"resraise()", "Error(TODO: unhandled rescript exception)")
|
||||
testDescEvalToBe(
|
||||
"javascript exception",
|
||||
"jsraise('div by 0')",
|
||||
"Error(JS Exception: Error: 'div by 0')",
|
||||
)
|
||||
testDescEvalToBe("rescript exception", "resraise()", "Error(TODO: unhandled rescript exception)")
|
||||
})
|
||||
|
|
|
@ -9,20 +9,8 @@ let parse: string => result<expression, Reducer_ErrorValue.t>
|
|||
module MapString = Belt.Map.String
|
||||
type bindings = MapString.t<unit>
|
||||
let defaultBindings: bindings
|
||||
let reduceValueList: list<expressionValue> => result<
|
||||
expressionValue,
|
||||
Reducer_ErrorValue.t,
|
||||
>
|
||||
let reduceExpression: (expression, 'a) => result<
|
||||
expressionValue,
|
||||
Reducer_ErrorValue.t,
|
||||
>
|
||||
let evalWBindingsExpression: (expression, 'a) => result<
|
||||
expressionValue,
|
||||
Reducer_ErrorValue.t,
|
||||
>
|
||||
let evalWBindings: (string, bindings) => Result.t<
|
||||
expressionValue,
|
||||
Reducer_ErrorValue.t,
|
||||
>
|
||||
let reduceValueList: list<expressionValue> => result<expressionValue, Reducer_ErrorValue.t>
|
||||
let reduceExpression: (expression, 'a) => result<expressionValue, Reducer_ErrorValue.t>
|
||||
let evalWBindingsExpression: (expression, 'a) => result<expressionValue, Reducer_ErrorValue.t>
|
||||
let evalWBindings: (string, bindings) => Result.t<expressionValue, Reducer_ErrorValue.t>
|
||||
let eval: string => Result.t<expressionValue, Reducer_ErrorValue.t>
|
||||
|
|
|
@ -54,7 +54,10 @@ let rec fromNode = (mathJsNode: Parse.node): result<expression, errorValue> =>
|
|||
Ok(list{}),
|
||||
(racc, currentPropertyMathJsNode) =>
|
||||
racc->Result.flatMap(acc =>
|
||||
fromNode(currentPropertyMathJsNode)->Result.map(propertyCode => list{propertyCode, ...acc})
|
||||
fromNode(currentPropertyMathJsNode)->Result.map(propertyCode => list{
|
||||
propertyCode,
|
||||
...acc,
|
||||
})
|
||||
),
|
||||
)
|
||||
rpropertyCodeList->Result.map(propertyCodeList => ExtressionT.EList(propertyCodeList))
|
||||
|
|
|
@ -23,7 +23,10 @@ let rec toString = aValue =>
|
|||
| EvSymbol(aString) => `:${aString}`
|
||||
| EvArray(anArray) => {
|
||||
let args =
|
||||
anArray->Belt.Array.map(each => toString(each))->Extra_Array.interperse(", ")->Js.String.concatMany("")
|
||||
anArray
|
||||
->Belt.Array.map(each => toString(each))
|
||||
->Extra_Array.interperse(", ")
|
||||
->Js.String.concatMany("")
|
||||
`[${args}]`
|
||||
}
|
||||
| EvRecord(aRecord) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user