Test macro with logic

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

View File

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

View File

@@ -379,4 +379,17 @@
(defun _testDefmacro []
(Assert.equals 5 (func5))
(Assert.equals "hello" (funcHello)))
(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")))