1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package org.glavo.javah;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RegexTests {
@Test
void testSimpleNamePattern() {
String[] names = {
"A", "a", "ABC", "AbC", "类名称", "_(*)", "a b c $ d ,", "<a"
};
String[] wrongNames = {
"", "A.B", "[A", "A;B", "A/B"
};
for (String name : names) {
assertTrue(Utils.SIMPLE_NAME_PATTERN.matcher(name).matches()
, String.format("'%s' match simple name pattern failed", name));
}
for (String name : wrongNames) {
assertFalse(Utils.SIMPLE_NAME_PATTERN.matcher(name).matches(),
String.format("'%s' match simple name pattern failed", name));
}
}
@Test
void testFullNamePattern() {
String[] names = {
"A", "a", "ABC", "AbC", "类名称", "_(*)", "a b c $ d ,",
"A.B.C", "A.bcd.E", "包1.包2.类名称", "_().B"
};
String[] wrongNames = {
"", "A..B", "A.", ".A", "[A", "A;B", "A/B"
};
for (String name : names) {
assertTrue(Utils.FULL_NAME_PATTERN.matcher(name).matches(),
String.format("'%s' match full name pattern failed", name));
}
for (String name : wrongNames) {
assertFalse(Utils.FULL_NAME_PATTERN.matcher(name).matches(),
String.format("'%s' match full name pattern failed", name));
}
}
@Test
void testMethodNamePattern() {
String[] names = {
"A", "a", "ABC", "AbC", "类名称", "_(*)", "a b c $ d ,", "<init>", "<cinit>"
};
String[] wrongNames = {
"", "A.B", "[A", "A;B", "A/B", "<", "b<a"
};
for (String name : names) {
assertTrue(Utils.METHOD_NAME_PATTERN.matcher(name).matches()
, String.format("'%s' match simple name pattern failed", name));
}
for (String name : wrongNames) {
assertFalse(Utils.METHOD_NAME_PATTERN.matcher(name).matches(),
String.format("'%s' match simple name pattern failed", name));
}
}
}
|