diff options
author | d9k <d9k@ya.ru> | 2018-05-04 22:57:53 +0300 |
---|---|---|
committer | d9k <d9k@ya.ru> | 2018-05-04 22:57:53 +0300 |
commit | 56b5189cb9f188a1064296fea3d239a1ae8b7f79 (patch) | |
tree | c80a263a50ab78f92a09e52607782684987c8c6f | |
parent | a5ebacddc49660f97bfe5e97e3bdfd264803372f (diff) | |
download | valua-56b5189cb9f188a1064296fea3d239a1ae8b7f79.tar.gz valua-56b5189cb9f188a1064296fea3d239a1ae8b7f79.tar.bz2 valua-56b5189cb9f188a1064296fea3d239a1ae8b7f79.zip |
converted spaces to tabs with `find -name \*.lua -exec bash -c 'unexpand --first-only --tabs=2 "$0" | tee "$0"' {} \;`
-rw-r--r-- | valua-test.lua | 4 | ||||
-rw-r--r-- | valua.lua | 24 |
2 files changed, 14 insertions, 14 deletions
diff --git a/valua-test.lua b/valua-test.lua index 307cd1a..fa0cfb9 100644 --- a/valua-test.lua +++ b/valua-test.lua @@ -63,8 +63,8 @@ local tests = { {v:new().contains(" "), {2,false, 1,true}}, {v:new().no_white(), {1,false, 2,true}}, {v:new().datetime(), {19,true, 9,false}}, - {v:new().number().min(45).optional(), {2,false, 6,false, 7,true, 4,true}}, - {v:new().string().optional(), {14,false, 1,true, 4,true}}, + {v:new().number().min(45).optional(), {2,false, 6,false, 7,true, 4,true}}, + {v:new().string().optional(), {14,false, 1,true, 4,true}}, } for n,t in ipairs(tests) do @@ -41,12 +41,12 @@ function valua:new(obj) --saves a function named _<index> with its args in a funcs table, to be used later when validating return function(...) local args = pack(...) - if k == 'optional' then - obj.allow_nil = true - else - local f = function(value) return valua['_'..k](value, unpack(args, 1, args.n)) end - tinsert(t.funcs,f) - end + if k == 'optional' then + obj.allow_nil = true + else + local f = function(value) return valua['_'..k](value, unpack(args, 1, args.n)) end + tinsert(t.funcs,f) + end return t end end @@ -54,12 +54,12 @@ function valua:new(obj) -- __call will run only when the value is validated self.__call = function(t,value) local res = true - local err = nil - local fres + local err = nil + local fres - if value == nil and t.allow_nil then - return res, err - end + if value == nil and t.allow_nil then + return res, err + end -- iterates through all chained validations funcs that were packed, passing the value to be validated for _,f in ipairs(t.funcs) do @@ -74,7 +74,7 @@ function valua:new(obj) return res,err end obj.funcs = {} - obj.allow_nil = false + obj.allow_nil = false return obj end -- |