@@ -12,37 +12,37 @@ import {
12
12
import { buildRegex } from '../../builders' ;
13
13
14
14
test ( '`any` character class' , ( ) => {
15
- expect ( any ) . toHavePattern ( '.' ) ;
16
- expect ( [ 'x' , any ] ) . toHavePattern ( 'x.' ) ;
17
- expect ( [ 'x' , any , 'x' ] ) . toHavePattern ( ' x.x' ) ;
15
+ expect ( any ) . toHavePattern ( / . / ) ;
16
+ expect ( [ 'x' , any ] ) . toHavePattern ( / x . / ) ;
17
+ expect ( [ 'x' , any , 'x' ] ) . toHavePattern ( / x .x / ) ;
18
18
} ) ;
19
19
20
20
test ( '`digit` character class' , ( ) => {
21
- expect ( digit ) . toHavePattern ( '\\d' ) ;
22
- expect ( [ 'x' , digit ] ) . toHavePattern ( 'x\\d' ) ;
23
- expect ( [ 'x' , digit , 'x' ] ) . toHavePattern ( 'x\\dx' ) ;
21
+ expect ( digit ) . toHavePattern ( / \d / ) ;
22
+ expect ( [ 'x' , digit ] ) . toHavePattern ( / x \d / ) ;
23
+ expect ( [ 'x' , digit , 'x' ] ) . toHavePattern ( / x \d x / ) ;
24
24
} ) ;
25
25
26
26
test ( '`word` character class' , ( ) => {
27
- expect ( word ) . toHavePattern ( '\\w' ) ;
28
- expect ( [ 'x' , word ] ) . toHavePattern ( 'x\\w' ) ;
29
- expect ( [ 'x' , word , 'x' ] ) . toHavePattern ( 'x\\wx' ) ;
27
+ expect ( word ) . toHavePattern ( / \w / ) ;
28
+ expect ( [ 'x' , word ] ) . toHavePattern ( / x \w / ) ;
29
+ expect ( [ 'x' , word , 'x' ] ) . toHavePattern ( / x \w x / ) ;
30
30
} ) ;
31
31
32
32
test ( '`whitespace` character class' , ( ) => {
33
- expect ( whitespace ) . toHavePattern ( '\\s' ) ;
34
- expect ( [ 'x' , whitespace ] ) . toHavePattern ( 'x\\s' ) ;
35
- expect ( [ 'x' , whitespace , 'x' ] ) . toHavePattern ( 'x\\sx' ) ;
33
+ expect ( whitespace ) . toHavePattern ( / \s / ) ;
34
+ expect ( [ 'x' , whitespace ] ) . toHavePattern ( / x \s / ) ;
35
+ expect ( [ 'x' , whitespace , 'x' ] ) . toHavePattern ( / x \s x / ) ;
36
36
} ) ;
37
37
38
38
test ( '`characterClass` base cases' , ( ) => {
39
- expect ( characterClass ( characterRange ( 'a' , 'z' ) ) ) . toHavePattern ( ' [a-z]' ) ;
39
+ expect ( characterClass ( characterRange ( 'a' , 'z' ) ) ) . toHavePattern ( / [ a - z ] / ) ;
40
40
expect ( characterClass ( characterRange ( 'a' , 'z' ) , characterRange ( 'A' , 'Z' ) ) ) . toHavePattern (
41
- ' [a-zA-Z]'
41
+ / [ a - z A - Z ] /
42
42
) ;
43
- expect ( characterClass ( characterRange ( 'a' , 'z' ) , anyOf ( '05' ) ) ) . toHavePattern ( ' [a-z05]' ) ;
43
+ expect ( characterClass ( characterRange ( 'a' , 'z' ) , anyOf ( '05' ) ) ) . toHavePattern ( / [ a - z 0 5 ] / ) ;
44
44
expect ( characterClass ( characterRange ( 'a' , 'z' ) , whitespace , anyOf ( '05' ) ) ) . toHavePattern (
45
- ' [a-z\\ s05]'
45
+ / [ a - z \s 0 5 ] /
46
46
) ;
47
47
} ) ;
48
48
@@ -53,9 +53,9 @@ test('`characterClass` throws on inverted arguments', () => {
53
53
} ) ;
54
54
55
55
test ( '`characterRange` base cases' , ( ) => {
56
- expect ( characterRange ( 'a' , 'z' ) ) . toHavePattern ( ' [a-z]' ) ;
57
- expect ( [ 'x' , characterRange ( '0' , '9' ) ] ) . toHavePattern ( ' x[0-9]' ) ;
58
- expect ( [ characterRange ( 'A' , 'F' ) , 'x' ] ) . toHavePattern ( ' [A-F]x' ) ;
56
+ expect ( characterRange ( 'a' , 'z' ) ) . toHavePattern ( / [ a - z ] / ) ;
57
+ expect ( [ 'x' , characterRange ( '0' , '9' ) ] ) . toHavePattern ( / x [ 0 - 9 ] / ) ;
58
+ expect ( [ characterRange ( 'A' , 'F' ) , 'x' ] ) . toHavePattern ( / [ A - F ] x / ) ;
59
59
} ) ;
60
60
61
61
test ( '`characterRange` throws on incorrect arguments' , ( ) => {
@@ -71,25 +71,25 @@ test('`characterRange` throws on incorrect arguments', () => {
71
71
} ) ;
72
72
73
73
test ( '`anyOf` base cases' , ( ) => {
74
- expect ( anyOf ( 'a' ) ) . toHavePattern ( 'a' ) ;
75
- expect ( [ 'x' , anyOf ( 'a' ) , 'x' ] ) . toHavePattern ( ' xax' ) ;
76
- expect ( anyOf ( 'ab' ) ) . toHavePattern ( ' [ab]' ) ;
77
- expect ( [ 'x' , anyOf ( 'ab' ) ] ) . toHavePattern ( ' x[ab]' ) ;
78
- expect ( [ 'x' , anyOf ( 'ab' ) , 'x' ] ) . toHavePattern ( ' x[ab]x' ) ;
74
+ expect ( anyOf ( 'a' ) ) . toHavePattern ( / a / ) ;
75
+ expect ( [ 'x' , anyOf ( 'a' ) , 'x' ] ) . toHavePattern ( / x a x / ) ;
76
+ expect ( anyOf ( 'ab' ) ) . toHavePattern ( / [ a b ] / ) ;
77
+ expect ( [ 'x' , anyOf ( 'ab' ) ] ) . toHavePattern ( / x [ a b ] / ) ;
78
+ expect ( [ 'x' , anyOf ( 'ab' ) , 'x' ] ) . toHavePattern ( / x [ a b ] x / ) ;
79
79
} ) ;
80
80
81
81
test ( '`anyOf` with quantifiers' , ( ) => {
82
- expect ( [ 'x' , oneOrMore ( anyOf ( 'abc' ) ) , 'x' ] ) . toHavePattern ( ' x[abc]+x' ) ;
83
- expect ( [ 'x' , optionally ( anyOf ( 'abc' ) ) , 'x' ] ) . toHavePattern ( ' x[abc]?x' ) ;
84
- expect ( [ 'x' , zeroOrMore ( anyOf ( 'abc' ) ) , 'x' ] ) . toHavePattern ( ' x[abc]*x' ) ;
82
+ expect ( [ 'x' , oneOrMore ( anyOf ( 'abc' ) ) , 'x' ] ) . toHavePattern ( / x [ a b c ] + x / ) ;
83
+ expect ( [ 'x' , optionally ( anyOf ( 'abc' ) ) , 'x' ] ) . toHavePattern ( / x [ a b c ] ? x / ) ;
84
+ expect ( [ 'x' , zeroOrMore ( anyOf ( 'abc' ) ) , 'x' ] ) . toHavePattern ( / x [ a b c ] * x / ) ;
85
85
} ) ;
86
86
87
87
test ( '`anyOf` escapes special characters' , ( ) => {
88
- expect ( anyOf ( 'abc-+.]\\' ) ) . toHavePattern ( ' [abc+.\\ ]\\\\-]' ) ;
88
+ expect ( anyOf ( 'abc-+.]\\' ) ) . toHavePattern ( / [ a b c + . \] \\ - ] / ) ;
89
89
} ) ;
90
90
91
91
test ( '`anyOf` moves hyphen to the last position' , ( ) => {
92
- expect ( anyOf ( 'a-bc' ) ) . toHavePattern ( ' [abc-]' ) ;
92
+ expect ( anyOf ( 'a-bc' ) ) . toHavePattern ( / [ a b c - ] / ) ;
93
93
} ) ;
94
94
95
95
test ( '`anyOf` throws on empty text' , ( ) => {
@@ -99,17 +99,17 @@ test('`anyOf` throws on empty text', () => {
99
99
} ) ;
100
100
101
101
test ( '`inverted` character class' , ( ) => {
102
- expect ( inverted ( anyOf ( 'a' ) ) ) . toHavePattern ( ' [^a]' ) ;
103
- expect ( inverted ( anyOf ( 'abc' ) ) ) . toHavePattern ( ' [^abc]' ) ;
102
+ expect ( inverted ( anyOf ( 'a' ) ) ) . toHavePattern ( / [ ^ a ] / ) ;
103
+ expect ( inverted ( anyOf ( 'abc' ) ) ) . toHavePattern ( / [ ^ a b c ] / ) ;
104
104
} ) ;
105
105
106
106
test ( '`inverted` character class double inversion' , ( ) => {
107
- expect ( inverted ( inverted ( anyOf ( 'a' ) ) ) ) . toHavePattern ( 'a' ) ;
108
- expect ( inverted ( inverted ( anyOf ( 'abc' ) ) ) ) . toHavePattern ( ' [abc]' ) ;
107
+ expect ( inverted ( inverted ( anyOf ( 'a' ) ) ) ) . toHavePattern ( / a / ) ;
108
+ expect ( inverted ( inverted ( anyOf ( 'abc' ) ) ) ) . toHavePattern ( / [ a b c ] / ) ;
109
109
} ) ;
110
110
111
111
test ( '`inverted` character class execution' , ( ) => {
112
- expect ( inverted ( anyOf ( 'a' ) ) ) . toMatchGroups ( 'aa' , [ ] ) ;
112
+ expect ( inverted ( anyOf ( 'a' ) ) ) . not . toMatchString ( 'aa' ) ;
113
113
expect ( inverted ( anyOf ( 'a' ) ) ) . toMatchGroups ( 'aba' , [ 'b' ] ) ;
114
114
} ) ;
115
115
0 commit comments