Skip to content

Commit

Permalink
Updated testsuite and changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFreezed committed Mar 19, 2022
1 parent 014bb45 commit 55f002d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
LuaPreprocess

v1.18 (2022-03-19)
Library:
- Added functions: loadResource(), evaluate(), pairsSorted(), sortNatural() and compareNatural().
- $symbol now accepts callable tables in addition to functions.
- Argument expressions for macros are no longer validated. This was inconsistent before as they were only validated when not containing preprocessor code, like @@foo(!!(bar)).

v1.17 (2021-11-22)
Library:
- Added predefined macros @@ASSERT() and @@LOG().
Expand Down
8 changes: 4 additions & 4 deletions preprocess.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[============================================================
--=
--= LuaPreprocess v1.17-dev - preprocessing library
--= LuaPreprocess v1.18 - preprocessing library
--= by Marcus 'ReFreezed' Thunström
--=
--= License: MIT (see the bottom of this file)
Expand Down Expand Up @@ -130,7 +130,7 @@



local PP_VERSION = "1.17.0-dev"
local PP_VERSION = "1.18.0"

local MAX_DUPLICATE_FILE_INSERTS = 1000 -- @Incomplete: Make this a parameter for processFile()/processString().

Expand Down Expand Up @@ -1491,8 +1491,8 @@ metaFuncs.serialize = serialize

-- evaluate()
-- value = evaluate( expression )
-- Evaluate an expression. Returns nil and a message on error.
-- Note that nil or false can also be returned if that's the value the expression results in!
-- Evaluate a Lua expression. Returns nil and a message on error.
-- Note that nil or false can also be returned as the first value if that's the value the expression results in!
metaFuncs.evaluate = evaluate

-- escapePattern()
Expand Down
52 changes: 52 additions & 0 deletions tests/suite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ doTest("Macros", function()
assertCodeOutput(assert(pp.processString{ code=[[ !(function ECHO(v) return v end) n = @@ECHO( !!("1")!!("+")!!("2") ) ]]}), [[n = 1+2]] )
assertCodeOutput(assert(pp.processString{ code=[[ !(function ECHO(v) return v end) n = @@ECHO{ !!("1")!!("+")!!("2") } ]]}), [[n = { 1+2 }]] )

-- Invalid code in arguments (which is ok).
local luaOut = assert(pp.processString{ code=[[
!function BINOP(operator, a, b) return a..operator..b end
v = @@BINOP(^, 3, 2)
]]})
assertCodeOutput(luaOut, [[v = 3^2]])

-- Invalid: Ambiguous syntax.
assert(not pp.processString{ code=[[
!function VOID() return "" end
Expand Down Expand Up @@ -427,6 +434,12 @@ doTest("Preprocessor symbols", function()
]]})
assertCodeOutput(luaOut, [[x = y]])

local luaOut = assert(pp.processString{ code=[[
!local FOO = setmetatable({}, {__call=function() return "y" end})
x = $FOO
]]})
assertCodeOutput(luaOut, [[x = y]])

-- Invalid: Symbols must result in strings.
assert(not pp.processString{ code=[[
!local BAD = 840
Expand All @@ -436,6 +449,10 @@ doTest("Preprocessor symbols", function()
!local function BAD() return 840 end
v = $BAD
]]})
assert(not pp.processString{ code=[[
!local BAD = {}
v = $BAD
]]})
end)


Expand Down Expand Up @@ -571,6 +588,41 @@ doTest("Output interception", function()
assert(not pp.processString{ code=[[ !stopInterceptingOutput() ]]})
end)

doTest("Resources and evaluation", function()
local pp = ppChunk()

assert(pp.processString{
code = [[ !assert(loadResource("x=x+1") == "x=x+1") ]],
onInsert = function(name) return name end,
})

assert(pp.processString{
code = [[ !x = 8 ; assert(evaluate("2^x") == 2^x) ]],
onInsert = function(name) return name end,
})
end)

doTest("Misc.", function()
local pp = ppChunk()

assert( ("foo9" < "foo10") == false)
assert(pp.compareNatural("foo9", "foo10") == true )

do
local keys = {"a2", "b", "a10", "-"}
local map = {a2=2, b=4, a10=3, ["-"]=1}
local count = 0

pp.sortNatural(keys)

for k, order in pp.pairsSorted(map) do
count = count + 1
assert(order == count)
assert(keys[order] == k)
end
end
end)



addLabel("Command line")
Expand Down

0 comments on commit 55f002d

Please sign in to comment.