1+ const assert = require ( 'node:assert' )
12const matchUtil = require ( '../src/utils/util.match' )
23
34const hostMap = matchUtil . domainMapRegexply ( {
@@ -6,48 +7,77 @@ const hostMap = matchUtil.domainMapRegexply({
67 '*.ccc.com' : true ,
78 '^.{1,3}ddd.com$' : true ,
89 '*.cn' : true ,
10+ '.github.com' : true ,
11+
12+ '*.eee.com' : true ,
13+ '.eee.com' : false , // 此配置将被忽略,因为有 '*.eee.com' 了,优先级更高
914} )
1015
1116console . 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 )
1232
13- console . log ( 'test1: aaa.com' )
1433const value11 = matchUtil . matchHostname ( hostMap , 'aaa.com' , 'test1.1' )
1534const value12 = matchUtil . matchHostname ( hostMap , 'aaaa.com' , 'test1.2' )
1635const 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 )
2040
21- console . log ( 'test2: *bbb.com' )
2241const value21 = matchUtil . matchHostname ( hostMap , 'bbb.com' , 'test2.1' )
2342const value22 = matchUtil . matchHostname ( hostMap , 'xbbb.com' , 'test2.2' )
2443const value23 = matchUtil . matchHostname ( hostMap , 'bbb.comx' , 'test2.3' )
2544const 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 )
3050
31- console . log ( 'test3: *.ccc.com' )
3251const value31 = matchUtil . matchHostname ( hostMap , 'ccc.com' , 'test3.1' )
3352const value32 = matchUtil . matchHostname ( hostMap , 'x.ccc.com' , 'test3.2' )
3453const 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 )
3858
39- console . log ( 'test4: ^.{1,3}ddd.com$' )
4059const value41 = matchUtil . matchHostname ( hostMap , 'ddd.com' , 'test4.1' )
4160const value42 = matchUtil . matchHostname ( hostMap , 'x.ddd.com' , 'test4.2' )
4261const 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 )
4666
47- console . log ( 'test5: *.cn' )
4867const value51 = matchUtil . matchHostname ( hostMap , 'eee.cn' , 'test5.1' )
4968const value52 = matchUtil . matchHostname ( hostMap , 'x.eee.cn' , 'test5.2' )
5069const 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