Test macro with logic

This commit is contained in:
2020-12-31 15:09:05 -07:00
parent de3577eb85
commit 880167b2ee
3 changed files with 19 additions and 1 deletions

View File

@@ -222,6 +222,7 @@ class Helpers {
interp.variables.set("k", k.forCaseParsing());
interp.variables.set("Helpers", Helpers);
interp.variables.set("Prelude", Prelude);
interp.variables.set("Lambda", Lambda);
interp.variables.set("Std", Std);
interps.push(interp);

View File

@@ -253,6 +253,10 @@ class BasicTestCase extends Test {
function testDefmacro() {
_testDefmacro();
}
function testDefmacroWithLogic() {
_testDefmacroWithLogic();
}
}
class BasicObject {

View File

@@ -380,3 +380,16 @@
(defun _testDefmacro []
(Assert.equals 5 (func5))
(Assert.equals "hello" (funcHello)))
(defvar &mut welcomeCount 0)
(defmacro macroWithLogic [name]
(deflocal message1 (ReaderExp.StrExp "Welcome "))
(deflocal message2 (ReaderExp.StrExp " (Guest #"))
(deflocal message3 (ReaderExp.StrExp ")"))
`(begin (set welcomeCount (+ welcomeCount 1))
(+ ,message1 ,name ,message2 (Std.string welcomeCount) ,message3)))
(defun _testDefmacroWithLogic []
(Assert.equals "Welcome Stevo (Guest #1)" (macroWithLogic "Stevo"))
(Assert.equals "Welcome Bob (Guest #2)" (macroWithLogic "Bob")))