Browse Source

Merge branch 'release/0.5.0'

tags/0.5.0^0
rucciva noneedtoknow 6 months ago
parent
commit
f4bac831ee
3 changed files with 46 additions and 2 deletions
  1. +2
    -2
      json-logic-lua-0.5.0-1.rockspec
  2. +14
    -0
      logic.lua
  3. +30
    -0
      spec/logic_spec.lua

json-logic-lua-0.4.0-1.rockspec → json-logic-lua-0.5.0-1.rockspec View File

@@ -1,8 +1,8 @@
package = "json-logic-lua"
version = "0.4.0-1"
version = "0.5.0-1"
source = {
url = "git://git.rucciva.one/rucciva/json-logic-lua",
tag = "0.4.0"
tag = "0.5.0"
}
description = {
summary = "json-logic lua port",

+ 14
- 0
logic.lua View File

@@ -512,6 +512,20 @@ operations['isArray'] = function(closure, v)
return closure.opts.is_array(v)
end

operations['toUpperCase'] = function(_, v)
if type(v) ~= "string" then
return nil
end
return string.upper(v)
end

operations['toLowerCase'] = function(_, v)
if type(v) ~= "string" then
return nil
end
return string.lower(v)
end

-- snake-case alias to be compatible with original json logic
operations['missing_some'] = operations['missingSome']
operations['is_array'] = operations['isArray']

+ 30
- 0
spec/logic_spec.lua View File

@@ -1216,6 +1216,36 @@ describe(
end
)

describe(
'json-logic string lower upper test',
function()
local function logic_test( test_table)
for i, t in ipairs(test_table) do
local res = logic_apply(logic.new_logic(t.operator, t.params), t.data)
assert.message('failed at index: ' .. i).are.equal(t.expected, res)
end
end
describe('given a string', function()
local test_table = {
{ operator = "toUpperCase", params = "something", expected = "SOMETHING"},
{ operator = "toUpperCase", params = "SOMETHING", expected = "SOMETHING"},
{ operator = "toUpperCase", params = "SomeThing", expected = "SOMETHING"},
{ operator = "toUpperCase", params = "someTHING", expected = "SOMETHING"},
{ operator = "toUpperCase", params = "sOmEtHiNg", expected = "SOMETHING"},
{ operator = "toLowerCase", params = "something", expected = "something"},
{ operator = "toLowerCase", params = "SOMETHING", expected = "something"},
{ operator = "toLowerCase", params = "SomeThing", expected = "something"},
{ operator = "toLowerCase", params = "someTHING", expected = "something"},
{ operator = "toLowerCase", params = "sOmEtHiNg", expected = "something"},
}
it('should correctly convert all character to uppercase or lowercase', function()
logic_test(test_table)
end)
end
)
end
)

describe(
'json-logic number test',
function()

Loading…
Cancel
Save