Browse Source
Merge in DESIGN/design from ~DESTINY.LIN/design:feature/x to feature/x * commit '07e01f472debcb051bd6244e020b98234989ad1b': REPORT-75998 完善正则表达式匹配,增加单元测试、增加控件事件中的回调函数中的JSfeature/x
Destiny.Lin-林锦龙
2 years ago
4 changed files with 143 additions and 3 deletions
@ -0,0 +1,107 @@ |
|||||||
|
package com.fr.design.actions.replace.utils; |
||||||
|
|
||||||
|
import junit.framework.TestCase; |
||||||
|
|
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Destiny.Lin |
||||||
|
* @version 11.0 |
||||||
|
* created by Destiny.Lin on 2022-09-30 |
||||||
|
*/ |
||||||
|
public class ShowValueUtilsTest extends TestCase { |
||||||
|
|
||||||
|
|
||||||
|
public void testChangeRegex() { |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"." |
||||||
|
*/ |
||||||
|
String regex = "."; |
||||||
|
String str = "=\"通配符:我(){}[]是*cu/r?y+单!^个字|+符串/?\\?.\""; |
||||||
|
Pattern pattern = Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher = pattern.matcher(str); |
||||||
|
assertTrue(matcher.find()); |
||||||
|
while (matcher.find()){ |
||||||
|
assertEquals(".", matcher.group()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"?" |
||||||
|
*/ |
||||||
|
regex = "??."; |
||||||
|
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher1 = pattern.matcher(str); |
||||||
|
assertTrue(matcher1.find()); |
||||||
|
while (matcher1.find()){ |
||||||
|
assertEquals("\\?.", matcher1.group()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"\" |
||||||
|
*/ |
||||||
|
regex = "?\\"; |
||||||
|
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher2 = pattern.matcher(str); |
||||||
|
assertTrue(matcher2.find()); |
||||||
|
while (matcher2.find()){ |
||||||
|
assertEquals("?\\", matcher2.group()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"/" |
||||||
|
*/ |
||||||
|
regex = "/"; |
||||||
|
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher3 = pattern.matcher(str); |
||||||
|
assertTrue(matcher3.find()); |
||||||
|
while (matcher3.find()){ |
||||||
|
assertEquals("/", matcher3.group()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"*" |
||||||
|
*/ |
||||||
|
regex = "*"; |
||||||
|
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher4 = pattern.matcher(str); |
||||||
|
assertTrue(matcher4.find()); |
||||||
|
while (matcher4.find()){ |
||||||
|
assertEquals("*", matcher4.group()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"(){}[]" |
||||||
|
*/ |
||||||
|
regex = "(){}[]"; |
||||||
|
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher5 = pattern.matcher(str); |
||||||
|
assertTrue(matcher5.find()); |
||||||
|
while (matcher5.find()){ |
||||||
|
assertEquals("(){}[]", matcher5.group()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"^" |
||||||
|
*/ |
||||||
|
regex = "!^"; |
||||||
|
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher6 = pattern.matcher(str); |
||||||
|
assertTrue(matcher6.find()); |
||||||
|
while (matcher6.find()){ |
||||||
|
assertEquals("!^", matcher6.group()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字符"|+" |
||||||
|
*/ |
||||||
|
regex = "|+"; |
||||||
|
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); |
||||||
|
Matcher matcher7 = pattern.matcher(str); |
||||||
|
assertTrue(matcher7.find()); |
||||||
|
while (matcher7.find()){ |
||||||
|
assertEquals("|+", matcher7.group()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue