test + fix for an ifLet regression

This commit is contained in:
2022-09-29 18:38:59 +00:00
parent 417fe965af
commit b2dde14fea
3 changed files with 25 additions and 14 deletions

View File

@@ -699,21 +699,24 @@ class Macros {
var gensym = b.symbol(); var gensym = b.symbol();
return b.let( return b.let(
[gensym, firstValue], [gensym, firstValue],
[b.callSymbol("case", [ [b.callSymbol("if", [
gensym, gensym,
b.call( b.callSymbol("case", [
b.callSymbol("when", [gensym, firstPattern]), [ gensym,
if (bindingList.length == 0) { b.call(firstPattern, [
thenExp; if (bindingList.length == 0) {
} else { thenExp;
ifLet(assertLet, wholeExp, [ } else {
b.list(bindingList) ifLet(assertLet, wholeExp, [
].concat(exps.slice(1)), k); b.list(bindingList)
} ].concat(exps.slice(1)), k);
]), }
b.callSymbol("otherwise", [ ]),
elseExp b.callSymbol("otherwise", [
]) elseExp
])
]),
elseExp
])]); ])]);
} }
macros["ifLet"] = ifLet.bind(false); macros["ifLet"] = ifLet.bind(false);

View File

@@ -364,6 +364,9 @@ class BasicTestCase extends Test {
_testQuickFractions(); _testQuickFractions();
} }
function testWhenLetGuards() {
_testWhenLetGuards();
}
} }

View File

@@ -689,3 +689,8 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(function _testQuickFractions [] (function _testQuickFractions []
(Assert.equals 0.5 (fHalf 1)) (Assert.equals 0.5 (fHalf 1))
(Assert.equals 0 (iHalf 1))) (Assert.equals 0 (iHalf 1)))
(function _testWhenLetGuards []
// Guards should be allowed in whenLet patterns
(whenLet [(when true 5) 5]
(Assert.pass)))