Browse Source

Merge branch 'release/0.5.0'

tags/0.5.0^0
rucciva noneedtoknow 1 month 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 @@
1 1
 package = "json-logic-lua"
2
-version = "0.4.0-1"
2
+version = "0.5.0-1"
3 3
 source = {
4 4
    url = "git://git.rucciva.one/rucciva/json-logic-lua",
5
-   tag = "0.4.0"
5
+   tag = "0.5.0"
6 6
 }
7 7
 description = {
8 8
    summary = "json-logic lua port",

+ 14
- 0
logic.lua View File

@@ -512,6 +512,20 @@ operations['isArray'] = function(closure, v)
512 512
     return closure.opts.is_array(v)
513 513
 end
514 514
 
515
+operations['toUpperCase'] = function(_, v)
516
+    if type(v) ~= "string" then
517
+        return nil
518
+    end
519
+    return string.upper(v)
520
+end
521
+
522
+operations['toLowerCase'] = function(_, v)
523
+    if type(v) ~= "string" then
524
+        return nil
525
+    end
526
+    return string.lower(v)
527
+end
528
+
515 529
 -- snake-case alias to be compatible with original json logic
516 530
 operations['missing_some'] = operations['missingSome']
517 531
 operations['is_array'] = operations['isArray']

+ 30
- 0
spec/logic_spec.lua View File

@@ -1216,6 +1216,36 @@ describe(
1216 1216
     end
1217 1217
 )
1218 1218
 
1219
+describe(
1220
+    'json-logic string lower upper test',
1221
+    function()
1222
+        local function logic_test( test_table)
1223
+            for i, t in ipairs(test_table) do
1224
+                local res = logic_apply(logic.new_logic(t.operator, t.params), t.data)
1225
+                assert.message('failed at index: ' .. i).are.equal(t.expected, res)
1226
+            end
1227
+        end
1228
+        describe('given a string', function()
1229
+            local test_table = {
1230
+                { operator = "toUpperCase", params = "something",  expected = "SOMETHING"},
1231
+                { operator = "toUpperCase", params = "SOMETHING",  expected = "SOMETHING"},
1232
+                { operator = "toUpperCase", params = "SomeThing",  expected = "SOMETHING"},
1233
+                { operator = "toUpperCase", params = "someTHING",  expected = "SOMETHING"},
1234
+                { operator = "toUpperCase", params = "sOmEtHiNg",  expected = "SOMETHING"},
1235
+                { operator = "toLowerCase", params = "something",  expected = "something"},
1236
+                { operator = "toLowerCase", params = "SOMETHING",  expected = "something"},
1237
+                { operator = "toLowerCase", params = "SomeThing",  expected = "something"},
1238
+                { operator = "toLowerCase", params = "someTHING",  expected = "something"},
1239
+                { operator = "toLowerCase", params = "sOmEtHiNg",  expected = "something"},
1240
+            }
1241
+            it('should correctly convert all character to uppercase or lowercase', function()
1242
+                logic_test(test_table)
1243
+            end)
1244
+        end
1245
+    )
1246
+    end
1247
+)
1248
+
1219 1249
 describe(
1220 1250
     'json-logic number test',
1221 1251
     function()

Loading…
Cancel
Save