2022-04-17 17:24:39 +00:00
|
|
|
open Jest
|
|
|
|
open Reducer_TestHelpers
|
|
|
|
|
2022-04-21 17:28:29 +00:00
|
|
|
describe("Parse for Bindings", () => {
|
2022-04-17 18:32:47 +00:00
|
|
|
testParseOuterToBe(
|
|
|
|
"x",
|
2022-04-21 17:05:03 +00:00
|
|
|
"Ok((:$$bindExpression (:$$bindings) :x))",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testParseOuterToBe(
|
|
|
|
"x+1",
|
2022-04-21 17:05:03 +00:00
|
|
|
"Ok((:$$bindExpression (:$$bindings) (:add :x 1)))",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testParseOuterToBe(
|
|
|
|
"y = x+1; y",
|
2022-04-21 17:05:03 +00:00
|
|
|
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) :y))",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testParsePartialToBe(
|
|
|
|
"x",
|
2022-04-21 17:05:03 +00:00
|
|
|
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) :x) (:$exportVariablesExpression)))",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testParsePartialToBe(
|
|
|
|
"y=x",
|
2022-04-21 17:05:03 +00:00
|
|
|
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y :x)) (:$exportVariablesExpression)))",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testParsePartialToBe(
|
|
|
|
"y=x+1",
|
2022-04-21 17:05:03 +00:00
|
|
|
"Ok((:$$bindExpression (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) (:$exportVariablesExpression)))",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testParsePartialToBe(
|
|
|
|
"y = x+1; z = y",
|
2022-04-21 17:05:03 +00:00
|
|
|
"Ok((:$$bindExpression (:$$bindStatement (:$$bindStatement (:$$bindings) (:$let :y (:add :x 1))) (:$let :z :y)) (:$exportVariablesExpression)))",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
})
|
2022-04-17 17:24:39 +00:00
|
|
|
|
2022-04-21 17:28:29 +00:00
|
|
|
Only.describe("Eval with Bindings", () => {
|
2022-04-17 18:32:47 +00:00
|
|
|
testEvalBindingsToBe(
|
|
|
|
"x",
|
2022-04-17 17:24:39 +00:00
|
|
|
list{("x", ExpressionValue.EvNumber(1.))},
|
2022-04-21 17:28:29 +00:00
|
|
|
"Ok(1)",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testEvalBindingsToBe(
|
2022-04-17 17:24:39 +00:00
|
|
|
"x+1",
|
|
|
|
list{("x", ExpressionValue.EvNumber(1.))},
|
2022-04-21 17:28:29 +00:00
|
|
|
"Ok(2)",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
|
|
|
testEvalBindingsToBe(
|
|
|
|
"y = x+1; y",
|
|
|
|
list{("x", ExpressionValue.EvNumber(1.))},
|
2022-04-21 17:28:29 +00:00
|
|
|
"Ok(2)",
|
2022-04-17 18:32:47 +00:00
|
|
|
)
|
2022-04-21 17:28:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("Eval Partial", () => {
|
2022-04-17 18:32:47 +00:00
|
|
|
testEvalPartialBindingsToBe(
|
|
|
|
"x",
|
|
|
|
list{("x", ExpressionValue.EvNumber(1.))},
|
|
|
|
"????",
|
|
|
|
)
|
|
|
|
testEvalPartialBindingsToBe(
|
|
|
|
"y=x",
|
|
|
|
list{("x", ExpressionValue.EvNumber(1.))},
|
|
|
|
"????",
|
|
|
|
)
|
|
|
|
testEvalBindingsToBe(
|
|
|
|
"y=x+1",
|
|
|
|
list{("x", ExpressionValue.EvNumber(1.))},
|
|
|
|
"????",
|
|
|
|
)
|
|
|
|
testEvalBindingsToBe(
|
|
|
|
"y = x+1; z = y",
|
|
|
|
list{("x", ExpressionValue.EvNumber(1.))},
|
|
|
|
"????",
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|