forked from DmitrySoshnikov/regexp-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator-basic-test.js
181 lines (143 loc) · 3.08 KB
/
generator-basic-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* The MIT License (MIT)
* Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
const parser = require('../../parser');
const generator = require('..');
function test(re) {
const reStr = re.toString();
const parsed = parser.parse(reStr);
const generated = generator.generate(parsed);
expect(generated).toBe(reStr);
}
describe('generator-basic', () => {
it('simple char', () => {
test(/a/);
});
it('space char', () => {
test(/ /);
});
it('escaped char', () => {
test(/\z/);
});
it('unicode char', () => {
test(/\u0036/);
});
it('hex char', () => {
test(/\x3B/);
});
it('octal char', () => {
test(/\073/);
});
it('meta char', () => {
test(/\n/);
test(/\r/);
test(/\s/);
test(/\S/);
test(/\d/);
test(/\D/);
test(/\w/);
test(/\W/);
test(/\v/);
test(/\f/);
});
it('alternative', () => {
test(/abc/);
});
it('disjunction', () => {
test(/a|b/);
});
it('disjunction - empty left', () => {
test(/|a/);
});
it('disjunction - empty right', () => {
test(/a|/);
});
it('capturing group', () => {
test(/(ab)/);
});
it('empty capturing group', () => {
test(/()/);
});
it('non-capturing group', () => {
test(/(?:ab)/);
});
it('named group', () => {
test('/(?<foo\\u003B\\u{003B}>bar)/u');
});
it('empty named group', () => {
test('/(?<foo\\u003B\\u{003B}>)/u');
});
it('empty non-capturing group', () => {
test(/(?:)/);
});
it('numeric backreference', () => {
test(/(a)\1/);
});
it('named backreference', () => {
test('/(?<foo\\u003B\\u{003B}>)\\k<foo\\u003B\\u{003B}>/u');
});
it('basic-assertion', () => {
test(/^/);
test(/$/);
test(/\b/);
test(/\B/);
});
it('positive character class', () => {
test(/[a-z0]/);
});
it('empty positive character class', () => {
/*eslint no-empty-character-class:0*/
test(/[]/);
});
it('negative character class', () => {
test(/[^a-z0]/);
});
it('empty negative character class', () => {
test(/[^]/);
});
it('positive lookahead assertion', () => {
test(/(?=abc)/);
});
it('empty positive lookahead assertion', () => {
test(/(?=)/);
});
it('negative lookahead assertion', () => {
test(/(?!abc)/);
});
it('empty negative lookahead assertion', () => {
test(/(?!)/);
});
it('positive lookbehind assertion', () => {
test('/(?<=abc)/');
});
it('empty positive lookbehind assertion', () => {
test('/(?<=)/');
});
it('negative lookbehind assertion', () => {
test('/(?<!abc)/');
});
it('empty negative lookbehind assertion', () => {
test('/(?<!)/');
});
it('simple greedy quantifier', () => {
test(/a?/);
test(/a*/);
test(/a+/);
});
it('simple non-greedy quantifier', () => {
test(/a??/);
test(/a*?/);
test(/a+?/);
});
it('range greedy quantifier', () => {
test(/a{1}/);
test(/a{1,}/);
test(/a{1,3}/);
});
it('range non-greedy quantifier', () => {
test(/a{1}?/);
test(/a{1,}?/);
test(/a{1,3}?/);
});
});