diff --git a/tests/util/built_in_functions_spec.lua b/tests/util/built_in_functions_spec.lua index 2a8781e..c496c91 100644 --- a/tests/util/built_in_functions_spec.lua +++ b/tests/util/built_in_functions_spec.lua @@ -200,4 +200,46 @@ describe("BuiltInFunctions tests", function () assert.is.False(BuiltInFunctions.IPMatch("192.168.2.124", "192.168.2.123")) assert.is.False(BuiltInFunctions.IPMatch("192.166.2.123", "192.168.2.123")) end) + + it("keyMatch5 tests", function () + assert.has_error(function () BuiltInFunctions.keyMatch5Func({"/foo"}) end, "Expected 2 arguments, but got 1") + assert.has_error(function () BuiltInFunctions.keyMatch5Func({"/foo/create/123", "/foo/*", "/foo/update/123"}) end, "Expected 2 arguments, but got 3") + assert.has_error(function () BuiltInFunctions.keyMatch5Func({"/parent/123", true}) end, "Argument must be a string") + + assert.is.True(BuiltInFunctions.keyMatch5("/parent/child?status=1&type=2", "/parent/child")) + assert.is.False(BuiltInFunctions.keyMatch5("/parent?status=1&type=2", "/parent/child")) + + assert.is.True(BuiltInFunctions.keyMatch5("/parent/child/?status=1&type=2", "/parent/child/")) + assert.is.False(BuiltInFunctions.keyMatch5("/parent/child/?status=1&type=2", "/parent/child")) + assert.is.False(BuiltInFunctions.keyMatch5("/parent/child?status=1&type=2", "/parent/child/")) + + assert.is.True(BuiltInFunctions.keyMatch5("/foo", "/foo")) + assert.is.True(BuiltInFunctions.keyMatch5("/foo", "/foo*")) + assert.is.False(BuiltInFunctions.keyMatch5("/foo", "/foo/*")) + assert.is.False(BuiltInFunctions.keyMatch5("/foo/bar", "/foo")) + assert.is.False(BuiltInFunctions.keyMatch5("/foo/bar", "/foo*")) + assert.is.True(BuiltInFunctions.keyMatch5("/foo/bar", "/foo/*")) + assert.is.False(BuiltInFunctions.keyMatch5("/foobar", "/foo")) + assert.is.False(BuiltInFunctions.keyMatch5("/foobar", "/foo*")) + assert.is.False(BuiltInFunctions.keyMatch5("/foobar", "/foo/*")) + + assert.is.False(BuiltInFunctions.keyMatch5("/", "/{resource}")) + assert.is.True(BuiltInFunctions.keyMatch5("/resource1", "/{resource}")) + assert.is.False(BuiltInFunctions.keyMatch5("/myid", "/{id}/using/{resId}")) + assert.is.True(BuiltInFunctions.keyMatch5("/myid/using/myresid", "/{id}/using/{resId}")) + + assert.is.False(BuiltInFunctions.keyMatch5("/proxy/myid", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2/res3", "/proxy/{id}/*")) + assert.is.False(BuiltInFunctions.keyMatch5("/proxy/", "/proxy/{id}/*")) + + assert.is.False(BuiltInFunctions.keyMatch5("/proxy/myid?status=1&type=2", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res?status=1&type=2", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2?status=1&type=2", "/proxy/{id}/*")) + assert.is.True(BuiltInFunctions.keyMatch5("/proxy/myid/res/res2/res3?status=1&type=2", "/proxy/{id}/*")) + assert.is.False(BuiltInFunctions.keyMatch5("/proxy/", "/proxy/{id}/*")) + end) end) \ No newline at end of file