This commit is contained in:
Umur Ozkul 2022-05-29 17:56:37 +02:00
parent ac3fa859c0
commit 00d7304b4b
4 changed files with 10 additions and 49 deletions

View File

@ -88,11 +88,7 @@ describe("block", () => {
) )
testMacroEval([], eBlock(list{exampleStatementY, exampleStatementZ}), "Ok({y: 1,z: 1})") testMacroEval([], eBlock(list{exampleStatementY, exampleStatementZ}), "Ok({y: 1,z: 1})")
// Block inside a block // Block inside a block
testMacro( testMacro([], eBlock(list{eBlock(list{exampleExpression})}), "Ok((:$$_bindExpression_$$ {1}))")
[],
eBlock(list{eBlock(list{exampleExpression})}),
"Ok((:$$_bindExpression_$$ {1}))",
)
testMacroEval([], eBlock(list{eBlock(list{exampleExpression})}), "Ok(1)") testMacroEval([], eBlock(list{eBlock(list{exampleExpression})}), "Ok(1)")
// Block assigned to a variable // Block assigned to a variable
testMacro( testMacro(

View File

@ -58,12 +58,7 @@ describe("Peggy to Expression", () => {
describe("multi-line", () => { describe("multi-line", () => {
testToExpression("x=1; 2", "{(:$_let_$ :x {1}); 2}", ~v="2", ()) testToExpression("x=1; 2", "{(:$_let_$ :x {1}); 2}", ~v="2", ())
testToExpression( testToExpression("x=1; y=2", "{(:$_let_$ :x {1}); (:$_let_$ :y {2})}", ~v="{x: 1,y: 2}", ())
"x=1; y=2",
"{(:$_let_$ :x {1}); (:$_let_$ :y {2})}",
~v="{x: 1,y: 2}",
(),
)
}) })
describe("variables", () => { describe("variables", () => {
@ -97,12 +92,7 @@ describe("Peggy to Expression", () => {
~v="['hello','world']", ~v="['hello','world']",
(), (),
) )
testToExpression( testToExpression("([0,1,2])[1]", "{(:$_atIndex_$ (:$_constructArray_$ (0 1 2)) 1)}", ~v="1", ())
"([0,1,2])[1]",
"{(:$_atIndex_$ (:$_constructArray_$ (0 1 2)) 1)}",
~v="1",
(),
)
}) })
describe("records", () => { describe("records", () => {
@ -174,16 +164,8 @@ describe("Peggy to Expression", () => {
}) })
describe("if then else", () => { describe("if then else", () => {
testToExpression( testToExpression("if true then 2 else 3", "{(:$$_ternary_$$ true {2} {3})}", ())
"if true then 2 else 3", testToExpression("if true then {2} else {3}", "{(:$$_ternary_$$ true {2} {3})}", ())
"{(:$$_ternary_$$ true {2} {3})}",
(),
)
testToExpression(
"if true then {2} else {3}",
"{(:$$_ternary_$$ true {2} {3})}",
(),
)
testToExpression( testToExpression(
"if false then {2} else if false then {4} else {5}", "if false then {2} else if false then {4} else {5}",
"{(:$$_ternary_$$ false {2} (:$$_ternary_$$ false {4} {5}))}", "{(:$$_ternary_$$ false {2} (:$$_ternary_$$ false {4} {5}))}",
@ -215,12 +197,7 @@ describe("Peggy to Expression", () => {
}) })
describe("lambda", () => { describe("lambda", () => {
testToExpression( testToExpression("{|x| x}", "{(:$$_lambda_$$ [x] {:x})}", ~v="lambda(x=>internal code)", ())
"{|x| x}",
"{(:$$_lambda_$$ [x] {:x})}",
~v="lambda(x=>internal code)",
(),
)
testToExpression( testToExpression(
"f={|x| x}", "f={|x| x}",
"{(:$_let_$ :f {(:$$_lambda_$$ [x] {:x})})}", "{(:$_let_$ :f {(:$$_lambda_$$ [x] {:x})})}",

View File

@ -3,10 +3,7 @@ open Reducer_TestHelpers
describe("Parse function assignment", () => { describe("Parse function assignment", () => {
testParseToBe("f(x)=x", "Ok({(:$_let_$ :f (:$$_lambda_$$ [x] {:x}))})") testParseToBe("f(x)=x", "Ok({(:$_let_$ :f (:$$_lambda_$$ [x] {:x}))})")
testParseToBe( testParseToBe("f(x)=2*x", "Ok({(:$_let_$ :f (:$$_lambda_$$ [x] {(:multiply 2 :x)}))})")
"f(x)=2*x",
"Ok({(:$_let_$ :f (:$$_lambda_$$ [x] {(:multiply 2 :x)}))})",
)
//MathJs does not allow blocks in function definitions //MathJs does not allow blocks in function definitions
}) })

View File

@ -139,18 +139,9 @@ describe("parse on distribution functions", () => {
"Ok((:$$_block_$$ (:dotSubtract (:normal 5 2) (:normal 5 1))))", "Ok((:$$_block_$$ (:dotSubtract (:normal 5 2) (:normal 5 1))))",
// TODO: !!! returns "Ok({(:dotPow (:normal 5 2) (:normal 5 1))})" // TODO: !!! returns "Ok({(:dotPow (:normal 5 2) (:normal 5 1))})"
) )
testParse( testParse("normal(5,2) .* normal(5,1)", "Ok({(:dotMultiply (:normal 5 2) (:normal 5 1))})")
"normal(5,2) .* normal(5,1)", testParse("normal(5,2) ./ normal(5,1)", "Ok({(:dotDivide (:normal 5 2) (:normal 5 1))})")
"Ok({(:dotMultiply (:normal 5 2) (:normal 5 1))})", testParse("normal(5,2) .^ normal(5,1)", "Ok({(:dotPow (:normal 5 2) (:normal 5 1))})")
)
testParse(
"normal(5,2) ./ normal(5,1)",
"Ok({(:dotDivide (:normal 5 2) (:normal 5 1))})",
)
testParse(
"normal(5,2) .^ normal(5,1)",
"Ok({(:dotPow (:normal 5 2) (:normal 5 1))})",
)
}) })
describe("equality", () => { describe("equality", () => {
testParse("5 == normal(5,2)", "Ok({(:equal 5 (:normal 5 2))})") testParse("5 == normal(5,2)", "Ok({(:equal 5 (:normal 5 2))})")