Skip to content

Commit 87fad95

Browse files
committed
Added tests for predefined macros.
1 parent b36e831 commit 87fad95

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/suite.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,40 @@ doTest("Macros", function()
378378
assert(not pp.processString{ code=[[ !(function Y() outputLua("y") ; return "z" end) x = @@Y() ]]})
379379
end)
380380

381+
doTest("Predefined macros", function()
382+
local pp = ppChunk()
383+
384+
-- @@ASSERT()
385+
local luaOut = assert(pp.processString{ code=[[
386+
@@ASSERT(foo)
387+
]]})
388+
assertCodeOutput(luaOut, [[if not (foo) then error("Assertion failed: foo") end]])
389+
390+
local luaOut = assert(pp.processString{ code=[[
391+
@@ASSERT(foo ~= "bad", "Bad foo: "..foo)
392+
]]})
393+
assertCodeOutput(luaOut, [[if not (foo ~= "bad") then error(("Bad foo: "..foo)) end]])
394+
395+
-- @@LOG()
396+
local luaOut = assert(pp.processString{ logLevel="error", code=[[
397+
@@LOG("warning", "Uh oh!")
398+
]]})
399+
assertCodeOutput(luaOut, [[]])
400+
401+
local luaOut = assert(pp.processString{ logLevel="warning", code=[[
402+
@@LOG("warning", "Uh oh!")
403+
]]})
404+
assertCodeOutput(luaOut, [[print("Uh oh!")]])
405+
406+
local luaOut = assert(pp.processString{ code=[[
407+
@@LOG("warning", "Number: %d", num)
408+
]]})
409+
assertCodeOutput(luaOut, [[print(string.format("Number: %d", num))]])
410+
411+
-- Invalid: Bad log level.
412+
assert(not pp.processString{ logLevel="bad", code=""})
413+
end)
414+
381415
doTest("Preprocessor symbols", function()
382416
local pp = ppChunk()
383417

0 commit comments

Comments
 (0)