Skip to content

Commit

Permalink
Added tests for predefined macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFreezed committed Nov 21, 2021
1 parent b36e831 commit 87fad95
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/suite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,40 @@ doTest("Macros", function()
assert(not pp.processString{ code=[[ !(function Y() outputLua("y") ; return "z" end) x = @@Y() ]]})
end)

doTest("Predefined macros", function()
local pp = ppChunk()

-- @@ASSERT()
local luaOut = assert(pp.processString{ code=[[
@@ASSERT(foo)
]]})
assertCodeOutput(luaOut, [[if not (foo) then error("Assertion failed: foo") end]])

local luaOut = assert(pp.processString{ code=[[
@@ASSERT(foo ~= "bad", "Bad foo: "..foo)
]]})
assertCodeOutput(luaOut, [[if not (foo ~= "bad") then error(("Bad foo: "..foo)) end]])

-- @@LOG()
local luaOut = assert(pp.processString{ logLevel="error", code=[[
@@LOG("warning", "Uh oh!")
]]})
assertCodeOutput(luaOut, [[]])

local luaOut = assert(pp.processString{ logLevel="warning", code=[[
@@LOG("warning", "Uh oh!")
]]})
assertCodeOutput(luaOut, [[print("Uh oh!")]])

local luaOut = assert(pp.processString{ code=[[
@@LOG("warning", "Number: %d", num)
]]})
assertCodeOutput(luaOut, [[print(string.format("Number: %d", num))]])

-- Invalid: Bad log level.
assert(not pp.processString{ logLevel="bad", code=""})
end)

doTest("Preprocessor symbols", function()
local pp = ppChunk()

Expand Down

0 comments on commit 87fad95

Please sign in to comment.