forked from Blankj/AndroidUtilCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegularUtilsTest.java
More file actions
100 lines (85 loc) · 3.05 KB
/
RegularUtilsTest.java
File metadata and controls
100 lines (85 loc) · 3.05 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.blankj.utilcode.utils;
import org.junit.Test;
import static com.blankj.utilcode.utils.RegularUtils.*;
import static com.google.common.truth.Truth.assertThat;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/8/16
* desc : RegularUtils单元测试
* </pre>
*/
public class RegularUtilsTest {
@Test
public void testIsMobileSimple() throws Exception {
assertThat(isMobileSimple("11111111111")).isTrue();
}
@Test
public void testIsMobileExact() throws Exception {
assertThat(isMobileExact("11111111111")).isFalse();
assertThat(isMobileExact("13888880000")).isTrue();
}
@Test
public void testIsTel() throws Exception {
assertThat(isTel("033-88888888")).isTrue();
assertThat(isTel("033-7777777")).isTrue();
assertThat(isTel("0444-88888888")).isTrue();
assertThat(isTel("0444-7777777")).isTrue();
assertThat(isTel("033 88888888")).isTrue();
assertThat(isTel("033 7777777")).isTrue();
assertThat(isTel("0444 88888888")).isTrue();
assertThat(isTel("0444 7777777")).isTrue();
assertThat(isTel("03388888888")).isTrue();
assertThat(isTel("0337777777")).isTrue();
assertThat(isTel("044488888888")).isTrue();
assertThat(isTel("04447777777")).isTrue();
assertThat(isTel("133-88888888")).isFalse();
assertThat(isTel("033-666666")).isFalse();
assertThat(isTel("0444-999999999")).isFalse();
}
@Test
public void testIsIDCard() throws Exception {
assertThat(isIDCard18("33698418400112523x")).isTrue();
assertThat(isIDCard18("336984184001125233")).isTrue();
assertThat(isIDCard18("336984184021125233")).isFalse();
}
@Test
public void testIsEmail() throws Exception {
assertThat(isEmail("blankj@qq.com")).isTrue();
assertThat(isEmail("blankj@qq")).isFalse();
}
@Test
public void testIsURL() throws Exception {
assertThat(isURL("http://blankj.com")).isTrue();
assertThat(isURL("http://blank")).isFalse();
}
@Test
public void testIsChz() throws Exception {
assertThat(isChz("我")).isTrue();
assertThat(isChz("wo")).isFalse();
}
@Test
public void testIsUsername() throws Exception {
assertThat(isUsername("小明233333")).isTrue();
assertThat(isUsername("小明")).isFalse();
assertThat(isUsername("小明233333_")).isFalse();
}
@Test
public void testIsDate() throws Exception {
assertThat(isDate("2016-08-16")).isTrue();
assertThat(isDate("2016-02-29")).isTrue();
assertThat(isDate("2015-02-29")).isFalse();
assertThat(isDate("2016-8-16")).isFalse();
}
@Test
public void testIsIP() throws Exception {
assertThat(isIP("255.255.255.0")).isTrue();
assertThat(isIP("256.255.255.0")).isFalse();
}
@Test
public void testIsMatch() throws Exception {
assertThat(isMatch("\\d?", "1")).isTrue();
assertThat(isMatch("\\d?", "a")).isFalse();
}
}