3
3
const assert = require ( 'assert' )
4
4
const SRL = require ( '../lib/Builder' )
5
5
6
- describe ( 'Builder Test ' , ( ) => {
6
+ describe ( 'Builder isMatching ' , ( ) => {
7
7
it ( 'Simple Phone Number Format' , ( ) => {
8
8
const regex = new SRL ( )
9
9
. startsWith ( )
@@ -15,12 +15,12 @@ describe('Builder Test', () => {
15
15
. digit ( ) . onceOrMore ( )
16
16
. mustEnd ( )
17
17
18
- assert . ok ( regex . test ( '+49 123-45' ) )
19
- assert . ok ( regex . exec ( '+492 1235-4' ) )
20
- assert . ok ( ! regex . test ( '+49 123 45' ) )
21
- assert . ok ( ! regex . exec ( '49 123-45' ) )
22
- assert . ok ( ! regex . test ( 'a+49 123-45' ) )
23
- assert . ok ( ! regex . test ( '+49 123-45b' ) )
18
+ assert . ok ( regex . isMatching ( '+49 123-45' ) )
19
+ assert . ok ( regex . isMatching ( '+492 1235-4' ) )
20
+ assert . ok ( ! regex . isMatching ( '+49 123 45' ) )
21
+ assert . ok ( ! regex . isMatching ( '49 123-45' ) )
22
+ assert . ok ( ! regex . isMatching ( 'a+49 123-45' ) )
23
+ assert . ok ( ! regex . isMatching ( '+49 123-45b' ) )
24
24
} )
25
25
26
26
it ( 'Simple Email Format' , ( ) => {
@@ -39,15 +39,14 @@ describe('Builder Test', () => {
39
39
. letter ( ) . atLeast ( 2 )
40
40
. mustEnd ( )
41
41
. caseInsensitive ( )
42
- . get ( ) // Use get() to test resulting RegExp object.
43
-
44
- assert . equal ( 'sample@example.com' . match ( regex ) [ 0 ] , 'sample@example.com' )
45
- assert . equal ( regex . exec ( 'super-He4vy.add+ress@top-Le.ve1.domains' ) , 'super-He4vy.add+ress@top-Le.ve1.domains' )
46
- assert . ok ( ! regex . test ( 'sample.example.com' ) )
47
- assert . ok ( ! regex . test ( 'missing@tld' ) )
48
- assert . ok ( ! regex . test ( 'hav ing@spac.es' ) )
49
- assert . ok ( ! regex . test ( 'no@pe.123' ) )
50
- assert . ok ( ! regex . test ( 'invalid@email.com123' ) )
42
+
43
+ assert . equal ( regex . getMatch ( 'sample@example.com' ) [ 0 ] , 'sample@example.com' )
44
+ assert . equal ( regex . getMatch ( 'super-He4vy.add+ress@top-Le.ve1.domains' ) [ 0 ] , 'super-He4vy.add+ress@top-Le.ve1.domains' )
45
+ assert . ok ( ! regex . isMatching ( 'sample.example.com' ) )
46
+ assert . ok ( ! regex . isMatching ( 'missing@tld' ) )
47
+ assert . ok ( ! regex . isMatching ( 'hav ing@spac.es' ) )
48
+ assert . ok ( ! regex . isMatching ( 'no@pe.123' ) )
49
+ assert . ok ( ! regex . isMatching ( 'invalid@email.com123' ) )
51
50
} )
52
51
53
52
it ( 'Capture Group' , ( ) => {
@@ -65,14 +64,13 @@ describe('Builder Test', () => {
65
64
query . letter ( ) . onceOrMore ( )
66
65
} )
67
66
. literally ( '.' )
68
- . get ( )
69
67
70
- assert . ok ( regex . test ( 'my favorite color: blue.' ) )
71
- assert . ok ( regex . test ( 'my favorite colour is green.' ) )
72
- assert . ok ( ! regex . test ( 'my favorite colour is green!' ) )
68
+ assert . ok ( regex . isMatching ( 'my favorite color: blue.' ) )
69
+ assert . ok ( regex . isMatching ( 'my favorite colour is green.' ) )
70
+ assert . ok ( ! regex . isMatching ( 'my favorite colour is green!' ) )
73
71
74
72
const testcase = 'my favorite colour is green. And my favorite color: yellow.'
75
- const matches = testcase . match ( regex )
73
+ const matches = regex . getMatch ( testcase )
76
74
assert . equal ( matches [ 1 ] , 'green' )
77
75
} )
78
76
@@ -86,12 +84,12 @@ describe('Builder Test', () => {
86
84
. tab ( )
87
85
. mustEnd ( )
88
86
. multiLine ( )
89
- . get ( )
87
+
90
88
const target = `
91
89
ba\t
92
90
aaabbb
93
91
`
94
- assert . ok ( regex . test ( target ) )
92
+ assert . ok ( regex . isMatching ( target ) )
95
93
96
94
const regex2 = new SRL ( )
97
95
. startsWith ( )
@@ -101,10 +99,10 @@ describe('Builder Test', () => {
101
99
. onceOrMore ( )
102
100
. literally ( 'b' )
103
101
. mustEnd ( )
104
- . get ( )
102
+
105
103
const target2 = `a
106
104
b`
107
- assert . ok ( regex2 . test ( target2 ) )
105
+ assert . ok ( regex2 . isMatching ( target2 ) )
108
106
} )
109
107
110
108
it ( 'Replace' , ( ) => {
@@ -133,28 +131,25 @@ describe('Builder Test', () => {
133
131
. whitespace ( ) . optional ( )
134
132
. lazy ( )
135
133
} )
136
- . get ( )
137
134
138
- const matches = ',, ' . match ( regex )
135
+ const matches = regex . getMatch ( ',, ' )
139
136
assert . equal ( matches [ 1 ] , ',,' )
140
137
assert . notEqual ( matches [ 1 ] , ',, ' )
141
138
142
139
const regex2 = new SRL ( )
143
140
. literally ( ',' )
144
141
. atLeast ( 1 )
145
142
. lazy ( )
146
- . get ( )
147
143
148
- const matches2 = regex2 . exec ( ',,,,,' )
144
+ const matches2 = regex2 . getMatch ( ',,,,,' )
149
145
assert . equal ( matches2 [ 0 ] , ',' )
150
146
assert . notEqual ( matches2 [ 0 ] , ',,,,,' )
151
147
152
148
} )
153
149
154
- it ( 'Global' , ( ) => {
150
+ it ( 'Global as Default ' , ( ) => {
155
151
const regex = new SRL ( )
156
152
. literally ( 'a' )
157
- . all ( )
158
153
. get ( )
159
154
160
155
let count = 0
@@ -169,9 +164,9 @@ describe('Builder Test', () => {
169
164
. raw ( 'b[a-z]r' )
170
165
. raw ( / \d + / )
171
166
172
- assert . ok ( regex . test ( 'foobzr123' ) )
173
- assert . ok ( regex . test ( 'foobar1' ) )
174
- assert . ok ( ! regex . test ( 'fooa' ) )
175
- assert . ok ( ! regex . test ( 'foobar' ) )
167
+ assert . ok ( regex . isMatching ( 'foobzr123' ) )
168
+ assert . ok ( regex . isMatching ( 'foobar1' ) )
169
+ assert . ok ( ! regex . isMatching ( 'fooa' ) )
170
+ assert . ok ( ! regex . isMatching ( 'foobar' ) )
176
171
} )
177
172
} )
0 commit comments