33const assert = require ( 'assert' )
44const SRL = require ( '../lib/Builder' )
55
6- describe ( 'Builder Test ' , ( ) => {
6+ describe ( 'Builder isMatching ' , ( ) => {
77 it ( 'Simple Phone Number Format' , ( ) => {
88 const regex = new SRL ( )
99 . startsWith ( )
@@ -15,12 +15,12 @@ describe('Builder Test', () => {
1515 . digit ( ) . onceOrMore ( )
1616 . mustEnd ( )
1717
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' ) )
2424 } )
2525
2626 it ( 'Simple Email Format' , ( ) => {
@@ -39,15 +39,14 @@ describe('Builder Test', () => {
3939 . letter ( ) . atLeast ( 2 )
4040 . mustEnd ( )
4141 . 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' ) )
5150 } )
5251
5352 it ( 'Capture Group' , ( ) => {
@@ -65,14 +64,13 @@ describe('Builder Test', () => {
6564 query . letter ( ) . onceOrMore ( )
6665 } )
6766 . literally ( '.' )
68- . get ( )
6967
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!' ) )
7371
7472 const testcase = 'my favorite colour is green. And my favorite color: yellow.'
75- const matches = testcase . match ( regex )
73+ const matches = regex . getMatch ( testcase )
7674 assert . equal ( matches [ 1 ] , 'green' )
7775 } )
7876
@@ -86,12 +84,12 @@ describe('Builder Test', () => {
8684 . tab ( )
8785 . mustEnd ( )
8886 . multiLine ( )
89- . get ( )
87+
9088 const target = `
9189 ba\t
9290 aaabbb
9391 `
94- assert . ok ( regex . test ( target ) )
92+ assert . ok ( regex . isMatching ( target ) )
9593
9694 const regex2 = new SRL ( )
9795 . startsWith ( )
@@ -101,10 +99,10 @@ describe('Builder Test', () => {
10199 . onceOrMore ( )
102100 . literally ( 'b' )
103101 . mustEnd ( )
104- . get ( )
102+
105103 const target2 = `a
106104 b`
107- assert . ok ( regex2 . test ( target2 ) )
105+ assert . ok ( regex2 . isMatching ( target2 ) )
108106 } )
109107
110108 it ( 'Replace' , ( ) => {
@@ -133,28 +131,25 @@ describe('Builder Test', () => {
133131 . whitespace ( ) . optional ( )
134132 . lazy ( )
135133 } )
136- . get ( )
137134
138- const matches = ',, ' . match ( regex )
135+ const matches = regex . getMatch ( ',, ' )
139136 assert . equal ( matches [ 1 ] , ',,' )
140137 assert . notEqual ( matches [ 1 ] , ',, ' )
141138
142139 const regex2 = new SRL ( )
143140 . literally ( ',' )
144141 . atLeast ( 1 )
145142 . lazy ( )
146- . get ( )
147143
148- const matches2 = regex2 . exec ( ',,,,,' )
144+ const matches2 = regex2 . getMatch ( ',,,,,' )
149145 assert . equal ( matches2 [ 0 ] , ',' )
150146 assert . notEqual ( matches2 [ 0 ] , ',,,,,' )
151147
152148 } )
153149
154- it ( 'Global' , ( ) => {
150+ it ( 'Global as Default ' , ( ) => {
155151 const regex = new SRL ( )
156152 . literally ( 'a' )
157- . all ( )
158153 . get ( )
159154
160155 let count = 0
@@ -169,9 +164,9 @@ describe('Builder Test', () => {
169164 . raw ( 'b[a-z]r' )
170165 . raw ( / \d + / )
171166
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' ) )
176171 } )
177172} )
0 commit comments