升级模糊匹配算法

This commit is contained in:
click33
2023-08-04 16:01:58 +08:00
parent f162834ded
commit 45a77612ef
2 changed files with 92 additions and 12 deletions

View File

@@ -113,16 +113,65 @@ public class SaFoxUtilTest {
Assertions.assertEquals(list6.get(0), dataList.get(dataList.size() - 1));
}
@Test
public void vagueMatch() {
Assertions.assertTrue(SaFoxUtil.vagueMatch("hello*", "hello"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("hello*", "hello world"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("hello*", "he"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("hello*", "hello*"));
Assertions.assertTrue(SaFoxUtil.vagueMatch(null, null));
Assertions.assertFalse(SaFoxUtil.vagueMatch(null, "hello"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("hello*", null));
}
@Test
public void vagueMatch() {
// 不模糊
Assertions.assertTrue(SaFoxUtil.vagueMatch("hello", "hello"));
// 正常模糊
Assertions.assertTrue(SaFoxUtil.vagueMatch("hello*", "hello"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("hello*", "hello world"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("hello*", "hello*"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("hello*", "he"));
// 带 -
Assertions.assertTrue(SaFoxUtil.vagueMatch("user-*", "user-"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user-*", "user-add"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user-*", "user-*"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user-*", "user"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user-*-add-*", "user-xx-add-1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user-*-add-*", "user-add-1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user-*", "usermgt-list"));
// 带 /
Assertions.assertTrue(SaFoxUtil.vagueMatch("user/*", "user/"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user/*", "user/add"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user/*", "user/*"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user/*", "user"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user/*/add/*", "user/xx/add/1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user/*/add/*", "user/add/1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user/*", "usermgt/list"));
// 带 :
Assertions.assertTrue(SaFoxUtil.vagueMatch("user:*", "user:"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user:*", "user:add"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user:*", "user:*"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user:*", "user"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user:*:add:*", "user:xx:add:1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user:*:add:*", "user:add:1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user:*", "usermgt:list"));
// 带 .
Assertions.assertTrue(SaFoxUtil.vagueMatch("user.*", "user."));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user.*", "user.add"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user.*", "user.*"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user.*", "user"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("user.*.add.*", "user.xx.add.1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user.*.add.*", "user.add.1"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("user.*", "usermgt.list"));
// 极端情况
Assertions.assertTrue(SaFoxUtil.vagueMatch(null, null));
Assertions.assertFalse(SaFoxUtil.vagueMatch(null, "hello"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("hello*", null));
// url 匹配
Assertions.assertTrue(SaFoxUtil.vagueMatch("*", "http://sa-sso-client1.com:9001/sso/login"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("http://sa-sso-client1.com:9001/*", "http://sa-sso-client1.com:9001/sso/login"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("http://sa-sso-client1.com:9001/*", "http://sa-sso-client1.com:9001/sso/login?name=1"));
Assertions.assertTrue(SaFoxUtil.vagueMatch("http://sa-sso-client1.com:9001/*", "http://sa-sso-client1.com:9001/sso/login?name=1&age=2"));
Assertions.assertFalse(SaFoxUtil.vagueMatch("http://sa-sso-client1.com:9001/*", "http://sa-sso-client1.com:9002"));
}
@Test
public void isWrapperType() {