1
+ const assert = require ( 'node:assert' )
1
2
const matchUtil = require ( '../src/utils/util.match' )
2
3
3
4
const hostMap = matchUtil . domainMapRegexply ( {
@@ -6,48 +7,77 @@ const hostMap = matchUtil.domainMapRegexply({
6
7
'*.ccc.com' : true ,
7
8
'^.{1,3}ddd.com$' : true ,
8
9
'*.cn' : true ,
10
+ '.github.com' : true ,
11
+
12
+ '*.eee.com' : true ,
13
+ '.eee.com' : false , // 此配置将被忽略,因为有 '*.eee.com' 了,优先级更高
9
14
} )
10
15
11
16
console . log ( hostMap )
17
+ assert . strictEqual ( hostMap [ '^.*bbb\\.com$' ] , true )
18
+ assert . strictEqual ( hostMap [ '^.*\\.ccc\\.com$' ] , true )
19
+ assert . strictEqual ( hostMap [ '^.{1,3}ddd.com$' ] , true )
20
+ assert . strictEqual ( hostMap [ '^.*\\.cn$' ] , true )
21
+ assert . strictEqual ( hostMap [ '^.*\\.github\\.com$' ] , true )
22
+ assert . strictEqual ( hostMap [ '^.*\\.github\\.com$' ] , true )
23
+ assert . strictEqual ( hostMap [ '^.*\\.eee\\.com$' ] , true )
24
+
25
+ const origin = hostMap . origin
26
+ assert . strictEqual ( origin [ 'aaa.com' ] , true )
27
+ assert . strictEqual ( origin [ '*bbb.com' ] , true )
28
+ assert . strictEqual ( origin [ '*.ccc.com' ] , true )
29
+ assert . strictEqual ( origin [ '*.cn' ] , true )
30
+ assert . strictEqual ( origin [ '*.github.com' ] , true )
31
+ assert . strictEqual ( origin [ '.eee.com' ] , undefined )
12
32
13
- console . log ( 'test1: aaa.com' )
14
33
const value11 = matchUtil . matchHostname ( hostMap , 'aaa.com' , 'test1.1' )
15
34
const value12 = matchUtil . matchHostname ( hostMap , 'aaaa.com' , 'test1.2' )
16
35
const value13 = matchUtil . matchHostname ( hostMap , 'aaaa.comx' , 'test1.3' )
17
- console . log ( value11 ) // true
18
- console . log ( value12 ) // undefined
19
- console . log ( value13 ) // undefined
36
+ console . log ( 'test1: aaa.com' )
37
+ assert . strictEqual ( value11 , true )
38
+ assert . strictEqual ( value12 , undefined )
39
+ assert . strictEqual ( value13 , undefined )
20
40
21
- console . log ( 'test2: *bbb.com' )
22
41
const value21 = matchUtil . matchHostname ( hostMap , 'bbb.com' , 'test2.1' )
23
42
const value22 = matchUtil . matchHostname ( hostMap , 'xbbb.com' , 'test2.2' )
24
43
const value23 = matchUtil . matchHostname ( hostMap , 'bbb.comx' , 'test2.3' )
25
44
const value24 = matchUtil . matchHostname ( hostMap , 'x.bbb.com' , 'test2.4' )
26
- console . log ( value21 ) // true
27
- console . log ( value22 ) // true
28
- console . log ( value23 ) // undefined
29
- console . log ( value24 ) // true
45
+ console . log ( 'test2: *bbb.com' )
46
+ assert . strictEqual ( value21 , true )
47
+ assert . strictEqual ( value22 , true )
48
+ assert . strictEqual ( value23 , undefined )
49
+ assert . strictEqual ( value24 , true )
30
50
31
- console . log ( 'test3: *.ccc.com' )
32
51
const value31 = matchUtil . matchHostname ( hostMap , 'ccc.com' , 'test3.1' )
33
52
const value32 = matchUtil . matchHostname ( hostMap , 'x.ccc.com' , 'test3.2' )
34
53
const value33 = matchUtil . matchHostname ( hostMap , 'xccc.com' , 'test3.3' )
35
- console . log ( value31 ) // true
36
- console . log ( value32 ) // true
37
- console . log ( value33 ) // undefined
54
+ console . log ( 'test3: *.ccc.com' )
55
+ assert . strictEqual ( value31 , true )
56
+ assert . strictEqual ( value32 , true )
57
+ assert . strictEqual ( value33 , undefined )
38
58
39
- console . log ( 'test4: ^.{1,3}ddd.com$' )
40
59
const value41 = matchUtil . matchHostname ( hostMap , 'ddd.com' , 'test4.1' )
41
60
const value42 = matchUtil . matchHostname ( hostMap , 'x.ddd.com' , 'test4.2' )
42
61
const value43 = matchUtil . matchHostname ( hostMap , 'xddd.com' , 'test4.3' )
43
- console . log ( value41 ) // undefined
44
- console . log ( value42 ) // true
45
- console . log ( value43 ) // true
62
+ console . log ( 'test4: ^.{1,3}ddd.com$' )
63
+ assert . strictEqual ( value41 , undefined )
64
+ assert . strictEqual ( value42 , true )
65
+ assert . strictEqual ( value43 , true )
46
66
47
- console . log ( 'test5: *.cn' )
48
67
const value51 = matchUtil . matchHostname ( hostMap , 'eee.cn' , 'test5.1' )
49
68
const value52 = matchUtil . matchHostname ( hostMap , 'x.eee.cn' , 'test5.2' )
50
69
const value53 = matchUtil . matchHostname ( hostMap , 'aaaa.cnet.com' , 'test5.3' )
51
- console . log ( value51 ) // true
52
- console . log ( value52 ) // true
53
- console . log ( value53 ) // undefined
70
+ console . log ( 'test5: *.cn' )
71
+ assert . strictEqual ( value51 , true )
72
+ assert . strictEqual ( value52 , true )
73
+ assert . strictEqual ( value53 , undefined )
74
+
75
+ const value61 = matchUtil . matchHostname ( hostMap , 'github.com' , 'test6.1' )
76
+ const value62 = matchUtil . matchHostname ( hostMap , 'api.github.com' , 'test6.2' )
77
+ const value63 = matchUtil . matchHostname ( hostMap , 'aa.bb.github.com' , 'test6.3' )
78
+ const value64 = matchUtil . matchHostname ( hostMap , 'aaagithub.com' , 'test6.4' )
79
+ console . log ( 'test6: .github.com' )
80
+ assert . strictEqual ( value61 , true )
81
+ assert . strictEqual ( value62 , true )
82
+ assert . strictEqual ( value63 , true )
83
+ assert . strictEqual ( value64 , undefined )
0 commit comments