Permalink
Browse files

tests now all work with -lpl.strict with both 5.1 and 5.2

  • Loading branch information...
1 parent 6f00e1c commit b8e56fffb6b15ba0220006f2b49d26187d39eb64 @stevedonovan committed May 12, 2012
Showing with 75 additions and 67 deletions.
  1. +51 −51 examples/testconfig.lua
  2. +1 −1 lua/pl/init.lua
  3. +1 −1 lua/pl/input.lua
  4. +1 −1 lua/pl/lapp.lua
  5. +1 −2 lua/pl/pretty.lua
  6. +6 −1 lua/pl/sip.lua
  7. +5 −1 lua/pl/stringio.lua
  8. +1 −1 lua/pl/stringx.lua
  9. +2 −2 lua/pl/tablex.lua
  10. +2 −2 lua/pl/xml.lua
  11. +2 −2 tests/test-date.lua
  12. +2 −2 tests/test-path.lua
@@ -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
+]]
+
+
View
@@ -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
View
@@ -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
View
@@ -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..'|'),
View
@@ -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.
@@ -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)
View
@@ -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
View
@@ -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 = {}
View
@@ -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
@@ -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
View
@@ -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
View
@@ -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;
@@ -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" };
View
@@ -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)
View
@@ -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 )

0 comments on commit b8e56ff

Please sign in to comment.