local subst = require 'pl.template'.substitute local List = require 'pl.List' local asserteq = require 'pl.test'.asserteq asserteq(subst([[ # for i = 1,2 do

Hello $(tostring(i))

# end ]],_G),[[

Hello 1

Hello 2

]]) asserteq(subst([[ ]],{ls = List{'john','alice','jane'}}),[[ ]]) -- can change the default escape from '#' so we can do C/C++ output. -- note that the environment can have a parent field. asserteq(subst([[ > for i,v in ipairs{'alpha','beta','gamma'} do cout << obj.${v} << endl; > end ]],{_parent=_G, _brackets='{}', _escape='>'}),[[ cout << obj.alpha << endl; cout << obj.beta << endl; cout << obj.gamma << endl; ]]) -- handle templates with a lot of substitutions asserteq(subst(("$(x)\n"):rep(300), {x = "y"}), ("y\n"):rep(300))