parse partial tested

This commit is contained in:
Umur Ozkul 2022-04-21 19:05:03 +02:00
parent 6b800c498e
commit 46f3ee3d2c
2 changed files with 16 additions and 20 deletions

View File

@ -1,34 +1,34 @@
open Jest
open Reducer_TestHelpers
Skip.describe("Parse for Bindings", () => {
Only.describe("Parse for Bindings", () => {
testParseOuterToBe(
"x",
"????",
"Ok((:$$bindExpression (:$$bindings) :x))",
)
testParseOuterToBe(
"x+1",
"????",
"Ok((:$$bindExpression (:$$bindings) (:add :x 1)))",
)
testParseOuterToBe(
"y = x+1; y",
"????",
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) :y))",
)
testParsePartialToBe(
"x",
"????",
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) :x) (:$exportVariablesExpression)))",
)
testParsePartialToBe(
"y=x",
"????",
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y :x)) (:$exportVariablesExpression)))",
)
testParsePartialToBe(
"y=x+1",
"????",
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) (:$exportVariablesExpression)))",
)
testParsePartialToBe(
"y = x+1; z = y",
"????",
"Ok((:$$bindExpression (:$$bindStatement (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) (:$let :z :y)) (:$exportVariablesExpression)))",
)
})

View File

@ -155,18 +155,17 @@ let fromPartialNode = (mathJsNode: Parse.node): result<expression, errorValue> =
Parse.castNodeType(mathJsNode)->Result.flatMap(typedMathJsNode => {
let casePartialBlockNode = (bNode: Parse.blockNode) => {
let blocksOrTags = bNode["blocks"]->Belt.Array.map(toTagOrNode)
let completed = Js.Array2.concatMany(
[BlockTag(ImportVariablesStatement)],
[blocksOrTags, [BlockTag(ExportVariablesExpression)]],
let completed = Js.Array2.concat(
blocksOrTags,
[BlockTag(ExportVariablesExpression)]
)
completed->caseTagOrNodes
}
let casePartialExpression = (node: Parse.node) => {
let completed = Js.Array2.concatMany(
[BlockTag(ImportVariablesStatement)],
[[BlockNode(node)], [BlockTag(ExportVariablesExpression)]],
)
let completed =
[BlockNode(node), BlockTag(ExportVariablesExpression)]
completed->caseTagOrNodes
}
@ -182,15 +181,12 @@ let fromOuterNode = (mathJsNode: Parse.node): result<expression, errorValue> =>
Parse.castNodeType(mathJsNode)->Result.flatMap(typedMathJsNode => {
let casePartialBlockNode = (bNode: Parse.blockNode) => {
let blocksOrTags = bNode["blocks"]->Belt.Array.map(toTagOrNode)
let completed = Js.Array2.concatMany([BlockTag(ImportVariablesStatement)], [blocksOrTags])
let completed = blocksOrTags
completed->caseTagOrNodes
}
let casePartialExpression = (node: Parse.node) => {
let completed = Js.Array2.concatMany(
[BlockTag(ImportVariablesStatement)],
[[BlockNode(node)]],
)
let completed = [BlockNode(node)]
completed->caseTagOrNodes
}