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})")
// Block inside a block
testMacro(
[],
eBlock(list{eBlock(list{exampleExpression})}),
"Ok((:$$_bindExpression_$$ {1}))",
)
testMacro([], eBlock(list{eBlock(list{exampleExpression})}), "Ok((:$$_bindExpression_$$ {1}))")
testMacroEval([], eBlock(list{eBlock(list{exampleExpression})}), "Ok(1)")
// Block assigned to a variable
testMacro(

View File

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

View File

@ -3,10 +3,7 @@ open Reducer_TestHelpers
describe("Parse function assignment", () => {
testParseToBe("f(x)=x", "Ok({(:$_let_$ :f (:$$_lambda_$$ [x] {:x}))})")
testParseToBe(
"f(x)=2*x",
"Ok({(:$_let_$ :f (:$$_lambda_$$ [x] {(:multiply 2 :x)}))})",
)
testParseToBe("f(x)=2*x", "Ok({(:$_let_$ :f (:$$_lambda_$$ [x] {(:multiply 2 :x)}))})")
//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))))",
// TODO: !!! returns "Ok({(:dotPow (:normal 5 2) (:normal 5 1))})"
)
testParse(
"normal(5,2) .* normal(5,1)",
"Ok({(:dotMultiply (: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))})",
)
testParse("normal(5,2) .* normal(5,1)", "Ok({(:dotMultiply (: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", () => {
testParse("5 == normal(5,2)", "Ok({(:equal 5 (:normal 5 2))})")