Skip to content

Commit

Permalink
tests now all work with -lpl.strict with both 5.1 and 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stevedonovan committed May 12, 2012
1 parent 6f00e1c commit b8e56ff
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 67 deletions.
102 changes: 51 additions & 51 deletions examples/testconfig.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
local stringio = require 'pl.stringio'
local config = require 'pl.config'

function dump(t,indent)
if type(t) == 'table' then
io.write(indent,'{\n')
local newindent = indent..' '
for k,v in pairs(t) do
io.write(newindent,k,'=')
dump(v,indent)
io.write('\n')
end
io.write(newindent,'},\n')
else
io.write(indent,t,'(',type(t),')')
end
end


function testconfig(test)
f = stringio.open(test)
c = config.read(f)
f:close()
dump(c,' ')
print '-----'
end

testconfig [[
; comment 2 (an ini file)
[section!]
bonzo.dog=20,30
config_parm=here we go again
depth = 2
[another]
felix="cat"
]]

testconfig [[
# this is a more Unix-y config file
fred = 1
alice = 2
home = /bonzo/dog/etc
]]

testconfig [[
# this is just a set of comma-separated values
1000,444,222
44,555,224
]]


local stringio = require 'pl.stringio'
local config = require 'pl.config'

function dump(t,indent)
if type(t) == 'table' then
io.write(indent,'{\n')
local newindent = indent..' '
for k,v in pairs(t) do
io.write(newindent,k,'=')
dump(v,indent)
io.write('\n')
end
io.write(newindent,'},\n')
else
io.write(indent,t,'(',type(t),')')
end
end


function testconfig(test)
local f = stringio.open(test)
local c = config.read(f)
f:close()
dump(c,' ')
print '-----'
end

testconfig [[
; comment 2 (an ini file)
[section!]
bonzo.dog=20,30
config_parm=here we go again
depth = 2
[another]
felix="cat"
]]

testconfig [[
# this is a more Unix-y config file
fred = 1
alice = 2
home = /bonzo/dog/etc
]]

testconfig [[
# this is just a set of comma-separated values
1000,444,222
44,555,224
]]


2 changes: 1 addition & 1 deletion lua/pl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ end

setmetatable(_G,gmt)

if _G.PENLIGHT_STRICT then require 'pl.strict' end
if rawget(_G,'PENLIGHT_STRICT') then require 'pl.strict' end
2 changes: 1 addition & 1 deletion lua/pl/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
local strfind = string.find
local strsub = string.sub
local strmatch = string.match
local pairs,type,unpack,tonumber = pairs,type,unpack or table.unpack,tonumber
local utils = require 'pl.utils'
local pairs,type,unpack,tonumber = pairs,type,unpack or table.unpack,tonumber
local patterns = utils.patterns
local io = io
local assert_arg = utils.assert_arg
Expand Down
2 changes: 1 addition & 1 deletion lua/pl/lapp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function lapp.process_options_string(str,args)
-- 'enum' type is a string which must belong to
-- one of several distinct values
local enums = ftype
enump = '|' .. enums .. '|'
local enump = '|' .. enums .. '|'
vtype = 'string'
constraint = function(s)
lapp.assert(enump:match('|'..s..'|'),
Expand Down
3 changes: 1 addition & 2 deletions lua/pl/pretty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ end
-- before or after the curly braces. A comment may occur beforehand.
-- An empty environment is used, and
-- any occurance of the keyword 'function' will be considered a problem.
-- If `plain` is set, then the string is 'free form' Lua statements, evaluated
-- in the given environment - the return value may be `nil`.
-- @param s {string} string of the form '{...}', with perhaps some whitespace
-- before or after the curly braces.
Expand All @@ -54,7 +53,7 @@ function pretty.read(s)
end
end
s = 'return '..s
local chunk,err = utils.load(s,'tbl','t',env or {})
local chunk,err = utils.load(s,'tbl','t',{})
if not chunk then return nil,err end
local SMT = save_string_index()
local ok,ret = pcall(chunk)
Expand Down
7 changes: 6 additions & 1 deletion lua/pl/sip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
--
-- @module pl.sip

if not rawget(_G,'loadstring') then -- Lua 5.2 full compatibility
loadstring = load
unpack = table.unpack
end

local append,concat = table.insert,table.concat
local concat = table.concat
local ipairs,loadstring,type,unpack = ipairs,loadstring or load,type,unpack
local ipairs,loadstring,type,unpack = ipairs,loadstring,type,unpack
local io,_G = io,_G
local print,rawget = print,rawget

Expand Down
6 changes: 5 additions & 1 deletion lua/pl/stringio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
-- See @{03-strings.md.File_style_I_O_on_Strings|the Guide}.
-- @module pl.stringio

local getmetatable,tostring,unpack,tonumber = getmetatable,tostring,unpack or table.unpack,tonumber
if not rawget(_G,'loadstring') then -- Lua 5.2 full compatibility
unpack = table.unpack
end

local getmetatable,tostring,unpack,tonumber = getmetatable,tostring,unpack,tonumber
local concat,append = table.concat,table.insert

local stringio = {}
Expand Down
2 changes: 1 addition & 1 deletion lua/pl/stringx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
--
-- Dependencies: `pl.utils`
-- @module pl.stringx
local utils = require 'pl.utils'
local string = string
local find = string.find
local type,setmetatable,getmetatable,ipairs,unpack = type,setmetatable,getmetatable,ipairs,unpack
Expand All @@ -16,7 +17,6 @@ local gsub = string.gsub
local rep = string.rep
local sub = string.sub
local concat = table.concat
local utils = require 'pl.utils'
local escape = utils.escape
local ceil = math.ceil
local _G = _G
Expand Down
4 changes: 2 additions & 2 deletions lua/pl/tablex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
--
-- Dependencies: `pl.utils`
-- @module pl.tablex
local utils = require ('pl.utils')
local getmetatable,setmetatable,require = getmetatable,setmetatable,require
local append,remove = table.insert,table.remove
local min,max = math.min,math.max
local pairs,type,unpack,next,select,tostring = pairs,type,unpack or table.unpack,next,select,tostring
local utils = require ('pl.utils')
local pairs,type,unpack,next,select,tostring = pairs,type,unpack,next,select,tostring
local function_arg = utils.function_arg
local Set = utils.stdmt.Set
local List = utils.stdmt.List
Expand Down
4 changes: 2 additions & 2 deletions lua/pl/xml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
-- Soft Dependencies: `lxp.lom` (fallback is to use basic Lua parser)
-- @module pl.xml

local split = require 'pl.utils'.split
local t_insert = table.insert;
local t_concat = table.concat;
local t_remove = table.remove;
Expand All @@ -42,13 +43,12 @@ local ipairs = ipairs;
local type = type;
local next = next;
local print = print;
local unpack = unpack or table.unpack;
local unpack = unpack;
local s_gsub = string.gsub;
local s_char = string.char;
local s_find = string.find;
local os = os;
local pcall,require,io = pcall,require,io
local split = require 'pl.utils'.split

local _M = {}
local Doc = { __type = "doc" };
Expand Down
4 changes: 2 additions & 2 deletions tests/test-date.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ print(d:month(7):last_day())
--]]

function check_df(fmt,str,no_check)
df = Date.Format(fmt)
d = df:parse(str)
local df = Date.Format(fmt)
local d = df:parse(str)
--print(str,d)
if not no_check then
asserteq(df:tostring(d),str)
Expand Down
4 changes: 2 additions & 2 deletions tests/test-path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function testpath(pth,p1,p2,p3)
asserteq(ext,p3)
end

testpath ([[c:\bonzo\dog_stuff\cat.txt]],[[c:\bonzo\dog_stuff]],'cat','.txt')
testpath ([[/bonzo/dog_stuff/cat.txt]],[[/bonzo/dog_stuff]],'cat','.txt')
testpath ([[/bonzo/dog/cat/fred.stuff]],'/bonzo/dog/cat','fred','.stuff')
testpath ([[../../alice/jones]],'../../alice','jones','')
testpath ([[alice]],'','alice','')
testpath ([[/path-to\dog\]],[[/path-to\dog]],'','')
testpath ([[/path-to/dog/]],[[/path-to/dog]],'','')

asserteq( path.isdir( "../docs" ), true )
asserteq( path.isdir( "../docs/config.ld" ), false )
Expand Down

0 comments on commit b8e56ff

Please sign in to comment.