@@ -3,15 +3,22 @@ import {
33 getNormalizedRomanNumber ,
44 prependWithZeros ,
55 romanToIntStr ,
6- NumberRegex ,
7- CompoundNumberDotRegex ,
8- CompoundNumberDashRegex ,
9- RomanNumberRegex ,
10- CompoundRomanNumberDotRegex ,
11- CompoundRomanNumberDashRegex
6+ NumberRegexStr ,
7+ CompoundNumberDotRegexStr ,
8+ CompoundNumberDashRegexStr ,
9+ RomanNumberRegexStr ,
10+ CompoundRomanNumberDotRegexStr ,
11+ CompoundRomanNumberDashRegexStr ,
12+ WordInASCIIRegexStr ,
13+ WordInAnyLanguageRegexStr
1214} from "./matchers" ;
15+ import { SortingSpecProcessor } from "./sorting-spec-processor" ;
1316
1417describe ( 'Plain numbers regexp' , ( ) => {
18+ let regexp : RegExp ;
19+ beforeEach ( ( ) => {
20+ regexp = new RegExp ( '^' + NumberRegexStr , 'i' ) ;
21+ } ) ;
1522 it . each ( [
1623 [ '' , null ] ,
1724 [ ' ' , null ] ,
@@ -23,7 +30,7 @@ describe('Plain numbers regexp', () => {
2330 [ '9' , '9' ] ,
2431 [ '7328964783268794325496783' , '7328964783268794325496783' ]
2532 ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
26- const match : RegExpMatchArray | null = s . match ( NumberRegex )
33+ const match : RegExpMatchArray | null = s . match ( regexp )
2734 if ( out ) {
2835 expect ( match ) . not . toBeNull ( )
2936 expect ( match ?. [ 1 ] ) . toBe ( out )
@@ -34,6 +41,10 @@ describe('Plain numbers regexp', () => {
3441} )
3542
3643describe ( 'Plain compound numbers regexp (dot)' , ( ) => {
44+ let regexp : RegExp ;
45+ beforeEach ( ( ) => {
46+ regexp = new RegExp ( '^' + CompoundNumberDotRegexStr , 'i' ) ;
47+ } ) ;
3748 it . each ( [
3849 [ '' , null ] ,
3950 [ ' ' , null ] ,
@@ -55,7 +66,7 @@ describe('Plain compound numbers regexp (dot)', () => {
5566 [ '56.78.-.1abc' , '56.78' ] ,
5667 [ '56.78-.1abc' , '56.78' ] ,
5768 ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
58- const match : RegExpMatchArray | null = s . match ( CompoundNumberDotRegex )
69+ const match : RegExpMatchArray | null = s . match ( regexp )
5970 if ( out ) {
6071 expect ( match ) . not . toBeNull ( )
6172 expect ( match ?. [ 1 ] ) . toBe ( out )
@@ -66,6 +77,10 @@ describe('Plain compound numbers regexp (dot)', () => {
6677} )
6778
6879describe ( 'Plain compound numbers regexp (dash)' , ( ) => {
80+ let regexp : RegExp ;
81+ beforeEach ( ( ) => {
82+ regexp = new RegExp ( '^' + CompoundNumberDashRegexStr , 'i' ) ;
83+ } ) ;
6984 it . each ( [
7085 [ '' , null ] ,
7186 [ ' ' , null ] ,
@@ -87,7 +102,7 @@ describe('Plain compound numbers regexp (dash)', () => {
87102 [ '56-78-.-1abc' , '56-78' ] ,
88103 [ '56-78.-1abc' , '56-78' ] ,
89104 ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
90- const match : RegExpMatchArray | null = s . match ( CompoundNumberDashRegex )
105+ const match : RegExpMatchArray | null = s . match ( regexp )
91106 if ( out ) {
92107 expect ( match ) . not . toBeNull ( )
93108 expect ( match ?. [ 1 ] ) . toBe ( out )
@@ -98,6 +113,10 @@ describe('Plain compound numbers regexp (dash)', () => {
98113} )
99114
100115describe ( 'Plain Roman numbers regexp' , ( ) => {
116+ let regexp : RegExp ;
117+ beforeEach ( ( ) => {
118+ regexp = new RegExp ( '^' + RomanNumberRegexStr , 'i' ) ;
119+ } ) ;
101120 it . each ( [
102121 [ '' , null ] ,
103122 [ ' ' , null ] ,
@@ -109,7 +128,7 @@ describe('Plain Roman numbers regexp', () => {
109128 [ 'iiiii' , 'iiiii' ] ,
110129 [ 'viviviv794325496783' , 'viviviv' ]
111130 ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
112- const match : RegExpMatchArray | null = s . match ( RomanNumberRegex )
131+ const match : RegExpMatchArray | null = s . match ( regexp )
113132 if ( out ) {
114133 expect ( match ) . not . toBeNull ( )
115134 expect ( match ?. [ 1 ] ) . toBe ( out )
@@ -120,6 +139,10 @@ describe('Plain Roman numbers regexp', () => {
120139} )
121140
122141describe ( 'Roman compound numbers regexp (dot)' , ( ) => {
142+ let regexp : RegExp ;
143+ beforeEach ( ( ) => {
144+ regexp = new RegExp ( '^' + CompoundRomanNumberDotRegexStr , 'i' ) ;
145+ } ) ;
123146 it . each ( [
124147 [ '' , null ] ,
125148 [ ' ' , null ] ,
@@ -143,7 +166,7 @@ describe('Roman compound numbers regexp (dot)', () => {
143166 [ 'xvx.d-.iabc' , 'xvx.d' ] ,
144167 [ 'xvx.d..iabc' , 'xvx.d' ] ,
145168 ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
146- const match : RegExpMatchArray | null = s . match ( CompoundRomanNumberDotRegex )
169+ const match : RegExpMatchArray | null = s . match ( regexp )
147170 if ( out ) {
148171 expect ( match ) . not . toBeNull ( )
149172 expect ( match ?. [ 1 ] ) . toBe ( out )
@@ -154,6 +177,10 @@ describe('Roman compound numbers regexp (dot)', () => {
154177} )
155178
156179describe ( 'Roman compound numbers regexp (dash)' , ( ) => {
180+ let regexp : RegExp ;
181+ beforeEach ( ( ) => {
182+ regexp = new RegExp ( '^' + CompoundRomanNumberDashRegexStr , 'i' ) ;
183+ } ) ;
157184 it . each ( [
158185 [ '' , null ] ,
159186 [ ' ' , null ] ,
@@ -177,7 +204,65 @@ describe('Roman compound numbers regexp (dash)', () => {
177204 [ 'xvx-d.-iabc' , 'xvx-d' ] ,
178205 [ 'xvx-d--iabc' , 'xvx-d' ]
179206 ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
180- const match : RegExpMatchArray | null = s . match ( CompoundRomanNumberDashRegex )
207+ const match : RegExpMatchArray | null = s . match ( regexp )
208+ if ( out ) {
209+ expect ( match ) . not . toBeNull ( )
210+ expect ( match ?. [ 1 ] ) . toBe ( out )
211+ } else {
212+ expect ( match ) . toBeNull ( )
213+ }
214+ } )
215+ } )
216+
217+ describe ( 'ASCII word regexp' , ( ) => {
218+ let regexp : RegExp ;
219+ beforeEach ( ( ) => {
220+ regexp = new RegExp ( '^' + WordInASCIIRegexStr , 'i' ) ;
221+ } ) ;
222+ it . each ( [
223+ [ '' , null ] ,
224+ [ ' ' , null ] ,
225+ [ ' I' , null ] , // leading spaces are not swallowed
226+ [ 'I ' , 'I' ] , // trailing spaces are swallowed
227+ [ 'Abc' , 'Abc' ] ,
228+ [ 'Sun' , 'Sun' ] ,
229+ [ 'Hello123' , 'Hello' ] ,
230+ [ 'John_' , 'John' ] ,
231+ [ 'Title.' , 'Title' ] ,
232+ [ 'Deutschstäder' , 'Deutschst' ] ,
233+ [ 'ItalianoàèéìòùÈ' , 'Italiano' ] ,
234+ [ 'PolskićśńĄł' , 'Polski' ]
235+ ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
236+ const match : RegExpMatchArray | null = s . match ( regexp )
237+ if ( out ) {
238+ expect ( match ) . not . toBeNull ( )
239+ expect ( match ?. [ 1 ] ) . toBe ( out )
240+ } else {
241+ expect ( match ) . toBeNull ( )
242+ }
243+ } )
244+ } )
245+
246+ describe ( 'Unicode word regexp' , ( ) => {
247+ let regexp : RegExp ;
248+ beforeEach ( ( ) => {
249+ regexp = new RegExp ( '^' + WordInAnyLanguageRegexStr , 'ui' ) ;
250+ } ) ;
251+ it . each ( [
252+ [ '' , null ] ,
253+ [ ' ' , null ] ,
254+ [ ' I' , null ] , // leading spaces are not swallowed
255+ [ 'I ' , 'I' ] , // trailing characters are ignored in unit test
256+ [ 'Abc' , 'Abc' ] ,
257+ [ 'Sun' , 'Sun' ] ,
258+ [ 'Hello123' , 'Hello' ] ,
259+ [ 'John_' , 'John' ] ,
260+ [ 'Title.' , 'Title' ] ,
261+ [ 'Deutschstäder_' , 'Deutschstäder' ] ,
262+ [ 'ItalianoàèéìòùÈ' , 'ItalianoàèéìòùÈ' ] ,
263+ [ 'PolskićśńĄł' , 'PolskićśńĄł' ]
264+ ] ) ( '%s => %s' , ( s : string , out : string | null ) => {
265+ const match : RegExpMatchArray | null = s . match ( regexp )
181266 if ( out ) {
182267 expect ( match ) . not . toBeNull ( )
183268 expect ( match ?. [ 1 ] ) . toBe ( out )
0 commit comments