-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicpats_test.go
446 lines (404 loc) · 21.2 KB
/
basicpats_test.go
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
package peg
import (
"strings"
"testing"
)
// Tests T, TI, TS, TSI, True, False, Dot, R, NR, S, NS, U.
func TestBasicPatterns(t *testing.T) {
ASC := "Ec|X,^X]ibC)$[S42\\]J`.rMe_@a2mEiri=>\\Dt0xaG^qc<C0qNnqzf_GVt^=SrMostRm5_$\x7flO&VZ'Q&a6h0;@[\\/O$oq/NFDK"
ARB := "ؿۼؗ٠خڥۊٛۉڭڏ٥ۧٽڞ۫ڤؗلږڊؘؙۨ۰پڅچؙ٠ۖؗ٤ِؔڷۮٴؒڇەڂٸ۳ؚدۺ١َ۵إ۽۾٤صګڦش٤۠ۂؽبضٝ۽ؽۑٕ۶ٖۧ؞ٙٮێۉا؟ث؈٬ۜھڃو؉ڈٍۄۻۥ٪ۭٱه"
CHS := "以仇价亓仕仡仯亅什亞亟仇亦亊亣仹任产仨仱亿仾仌事仔仐亽亓仨亇仯仉仔云亄仅从亊争亹仑从亾亊亟仢二亩亁仺令亏亶交仰仫仃亵仸亂京予亙亘亷仩他亗亍亷从二仰亏亝亇仴亜仭仍亘仪亹仆亹亘亳亙人亜仓亚亂亀产仼亀仔仯亍"
JPN := "うすせちぎそづぁぉぅだわりょめぽゐぷぷぶのらづうをざもうためそおどそをごんぁぃへにぞゑびこかまゅょゑすぢけをだづきぱびほきおとごぴつさひにろのわたるっぷぴつくかぼきふむぐゆよぷしみじぷきゆぇぼぽぬぽむ"
KRN := "픀쉀붏뙘췒삹늭쏐뵢쾙푃멥묶쿔봼즱끇섭챊힜싰윂묷뢥롹잌룈샳껪꼤홬퀩쁇뾩뤽눿아땧뜚됂퐭걻큼텿끝꾘븏뉿촂빅뗵홌굛찄햂굟흍뎍즠쬫쌂얝뮂긌뱍쉸경뺀횞찚쿤퀃핿샶패풄쐘뇙쉼쾕썤똵슻묌흥댍풲힆볎떄끙뷟큺쬔뛣곺떡뫀쓷씂"
data := []patternTestData{
{"", true, 0, false, ``, ``, T("")},
{"a", true, 0, false, ``, ``, T("")},
{"abcdefg", true, 3, false, ``, ``, T("abc")},
{"中国人", true, 6, false, ``, ``, T("中国")},
{"", true, 0, false, ``, ``, TI("")},
{"a", true, 0, false, ``, ``, TI("")},
{"A", true, 1, false, ``, ``, TI("a")},
{"a", true, 1, false, ``, ``, TI("A")},
{"Ё", true, 2, false, ``, ``, TI("ё")},
{"ſK", true, 5, false, ``, ``, TI("ſK")},
{"ß", true, 2, false, ``, ``, TI("ẞ")},
{"ѣ", true, 2, false, ``, ``, TI("Ѣ")},
{"aAåÅA", true, 8, false, ``, ``, TI("aaÅåa")},
{"", false, 0, false, ``, ``, TS()},
{"01", true, 2, false, ``, ``, TS(strings.Split("0/01/011/012/021/123/1234", "/")...)},
{"013", true, 2, false, ``, ``, TS(strings.Split("0/01/011/012/021/123/1234", "/")...)},
{"022", true, 1, false, ``, ``, TS(strings.Split("0/01/011/012/021/123/1234", "/")...)},
{"1234", true, 4, false, ``, ``, TS(strings.Split("0/01/011/012/021/123/1234", "/")...)},
{"true", true, 4, false, ``, ``, TS("true", "false")},
{"false", true, 5, false, ``, ``, TS("true", "false")},
{"", false, 0, false, ``, ``, TSI()},
{"True", true, 4, false, ``, ``, TSI("true", "false")},
{"False", true, 5, false, ``, ``, TSI("true", "false")},
{"åÅA", true, 6, false, ``, ``, TSI("Ååa", "Bbb")},
{"åÅA", true, 6, false, ``, ``, TSI("Ååa", "Bbb")},
{"bBb", true, 3, false, ``, ``, TSI("Ååa", "Bbb")},
{"å", true, 2, false, ``, ``, TSI("Ååa", "Å")},
{"a", true, 1, false, ``, ``, TSI("aaa", "A")},
{"", true, 0, false, ``, ``, True},
{"a", true, 0, false, ``, ``, True},
{"", false, 0, false, ``, ``, False},
{"a", false, 0, false, ``, ``, False},
{"", false, 0, false, ``, ``, Dot},
{"a", true, 1, false, ``, ``, Dot},
{"你好", true, 3, false, ``, ``, Dot},
// "\xe4\xbd\x20" is a bad utf-8 sequence,
// only one byte (unicode rune replacement) would be matched.
{"\xe4\xbd\x20", true, 1, false, ``, ``, Dot},
{"", false, 0, false, ``, ``, R('a', 'z')},
{"word", true, 1, false, ``, ``, R('a', 'z')},
{"h", true, 1, false, ``, ``, R('a', 'z', '0', '9')},
{"5", true, 1, false, ``, ``, R('a', 'z', '0', '9')},
{"H", false, 0, false, ``, ``, R('a', 'z', '0', '9')},
{"你好", false, 0, false, ``, ``, R('a', 'z')},
{"你好", true, 3, false, ``, ``, NR('a', 'z')},
{"", false, 0, false, ``, ``, NR('a', 'z')},
{"H", true, 1, false, ``, ``, NR('a', 'z', '0', '9')},
{"h", false, 0, false, ``, ``, NR('a', 'z', '0', '9')},
{"5", false, 0, false, ``, ``, NR('a', 'z', '0', '9')},
{"", false, 0, false, ``, ``, S("abc")},
{"a", true, 1, false, ``, ``, S("abc")},
{"c", true, 1, false, ``, ``, S("abc")},
{"好", true, 3, false, ``, ``, S("你好")},
{"你", true, 3, false, ``, ``, S("你好")},
{"x", true, 1, false, ``, ``, NS("abc")},
{"你", true, 3, false, ``, ``, NS("abc")},
{"你", false, 0, false, ``, ``, NS("你好")},
{"中国", true, 3, false, ``, ``, NS("你好")},
{"a", true, 1, false, ``, ``, S(ASC)},
{"۵", true, 2, false, ``, ``, S(ARB)},
{"京", true, 3, false, ``, ``, S(CHS)},
{"め", true, 3, false, ``, ``, S(JPN)},
{"아", true, 3, false, ``, ``, S(KRN)},
{"", false, 0, false, ``, ``, U()},
{"你好", true, 3, false, ``, ``, U("Letter")},
{"你好", true, 3, false, ``, ``, U("-Punct")},
{"。", false, 0, false, ``, ``, U("-Punct")},
{"、", true, 3, false, ``, ``, U("Punct")},
{" ", true, 1, false, ``, ``, U("White_Space")},
{"Hello", true, 1, false, ``, ``, U("Letter", "-Han")},
{"你好", false, 0, false, ``, ``, U("Letter", "-Han")},
}
for _, d := range data {
runPatternTestData(t, d)
}
}
// Tests Seq, Alt.
func TestSeqAlt(t *testing.T) {
data := []patternTestData{
{"", true, 0, false, ``, ``, Seq()},
{"", true, 0, false, ``, ``, Seq(True)},
{"", false, 0, false, ``, ``, Seq(False)},
{"", true, 0, false, ``, ``, Seq(True, True)},
{"", false, 0, false, ``, ``, Seq(True, False)},
{"", false, 0, false, ``, ``, Seq(False, True)},
{"", false, 0, false, ``, ``, Seq(False, False)},
{"AB", true, 2, false, ``, ``, Seq(T("A"), T("B"))},
{"AC", false, 0, false, ``, ``, Seq(T("A"), T("B"))},
{"", false, 0, false, ``, ``, Alt()},
{"", true, 0, false, ``, ``, Alt(True)},
{"", false, 0, false, ``, ``, Alt(False)},
{"", true, 0, false, ``, ``, Alt(True, True)},
{"", true, 0, false, ``, ``, Alt(True, False)},
{"", true, 0, false, ``, ``, Alt(False, True)},
{"", false, 0, false, ``, ``, Alt(False, False)},
{"AB", true, 1, false, ``, ``, Alt(T("A"), T("B"))},
{"AC", true, 1, false, ``, ``, Alt(T("A"), T("B"))},
{"BC", true, 1, false, ``, ``, Alt(T("A"), T("B"))},
{"CA", false, 0, false, ``, ``, Alt(T("A"), T("B"))},
}
for _, d := range data {
runPatternTestData(t, d)
}
}
// Tests Test, Not, SOL, EOL, EOF, B,
// And, Or, When, If, Switch
func TestPredicators(t *testing.T) {
data := []patternTestData{
{"", false, 0, false, ``, ``, Test(False)},
{"", true, 0, false, ``, ``, Test(True)},
{"", false, 0, false, ``, ``, Test(T("A"))},
{"A", true, 0, false, ``, ``, Test(T("A"))},
{"", true, 0, false, ``, ``, Not(False)},
{"", false, 0, false, ``, ``, Not(True)},
{"", true, 0, false, ``, ``, Not(T("A"))},
{"A", false, 0, false, ``, ``, Not(T("A"))},
{"", true, 0, false, ``, ``, SOL},
{"A", true, 0, false, ``, ``, SOL},
{"A", false, 0, false, ``, ``, Seq(Dot, SOL)},
{"AB", false, 0, false, ``, ``, Seq(Dot, SOL)},
{"A\nB", true, 2, false, ``, ``, Seq(Dot, Dot, SOL)},
{"A\rB", true, 2, false, ``, ``, Seq(Dot, Dot, SOL)},
{"A\r\nB", false, 0, false, ``, ``, Seq(Dot, Dot, SOL)},
{"", true, 0, false, ``, ``, EOL},
{"A", true, 1, false, ``, ``, Seq(Dot, EOL)},
{"AB", false, 0, false, ``, ``, Seq(Dot, EOL)},
{"A\nB", true, 1, false, ``, ``, Seq(Dot, EOL)},
{"A\rB", true, 1, false, ``, ``, Seq(Dot, EOL)},
{"A\r\nB", true, 1, false, ``, ``, Seq(Dot, EOL)},
{"A\r\nB", false, 0, false, ``, ``, Seq(Dot, Dot, EOL)},
{"", true, 0, false, ``, ``, EOF},
{"A", false, 0, false, ``, ``, EOF},
{"A", true, 1, false, ``, ``, Seq(Dot, EOF)},
{"A", true, 1, false, ``, ``, Seq(Dot, B(""))},
{"A", true, 1, false, ``, ``, Seq(Dot, B("A"))},
{"A", false, 0, false, ``, ``, Seq(Dot, B("B"))},
{"A", false, 0, false, ``, ``, Seq(Dot, B("AB"))},
{"A", false, 0, false, ``, ``, Seq(Dot, B("BA"))},
{"", true, 0, false, ``, ``, And()},
{"", true, 0, false, ``, ``, And(True, True)},
{"", false, 0, false, ``, ``, And(True, False)},
{"", false, 0, false, ``, ``, And(False, True)},
{"", false, 0, false, ``, ``, And(False, False)},
{"AB", false, 0, false, ``, ``, And(T("A"), T("B"))},
{"AB", true, 0, false, ``, ``, And(T("AB"), Dot)},
{"AB", false, 0, false, ``, ``, And(T("AB"), T("ABC"))},
{"ABC", true, 0, false, ``, ``, And(T("AB"), T("ABC"))},
{"", false, 0, false, ``, ``, Or()},
{"", true, 0, false, ``, ``, Or(True, True)},
{"", true, 0, false, ``, ``, Or(True, False)},
{"", true, 0, false, ``, ``, Or(False, True)},
{"", false, 0, false, ``, ``, Or(False, False)},
{"AB", true, 0, false, ``, ``, Or(T("A"), T("B"))},
{"AC", true, 0, false, ``, ``, Or(T("A"), T("B"))},
{"BC", true, 0, false, ``, ``, Or(T("A"), T("B"))},
{"CA", false, 0, false, ``, ``, Or(T("A"), T("B"))},
{"AB", true, 0, false, ``, ``, Or(T("AB"), T("ABC"))},
{"ABC", true, 2, false, ``, ``, Seq(Dot, When(B("A"), T("B")))},
{"AB", true, 2, false, ``, ``, When(Not(T("0")), Seq(U("-White_Space"), U("-White_Space")))},
{"0A", false, 0, false, ``, ``, When(Not(T("0")), Seq(U("-White_Space"), U("-White_Space")))},
{"A0", true, 2, false, ``, ``, When(Not(T("0")), Seq(U("-White_Space"), U("-White_Space")))},
{"0num", false, 0, false, ``, ``, If(R('0', '9'), T("num"), T("nan"))},
{"0nan", false, 0, false, ``, ``, If(R('0', '9'), T("num"), T("nan"))},
{"0num", true, 4, false, ``, ``, If(R('0', '9'), Seq(Dot, T("num")), Seq(Dot, T("nan")))},
{"0nan", false, 0, false, ``, ``, If(R('0', '9'), Seq(Dot, T("num")), Seq(Dot, T("nan")))},
{"anum", false, 0, false, ``, ``, If(R('0', '9'), Seq(Dot, T("num")), Seq(Dot, T("nan")))},
{"anan", true, 4, false, ``, ``, If(R('0', '9'), Seq(Dot, T("num")), Seq(Dot, T("nan")))},
{"0a", true, 2, false, ``, ``, Seq(Dot, Switch(B("0"), T("a")))},
{"0b", false, 0, false, ``, ``, Seq(Dot, Switch(B("0"), T("a")))},
{"1a", true, 1, false, ``, ``, Seq(Dot, Switch(B("0"), T("a")))},
{"1b", true, 1, false, ``, ``, Seq(Dot, Switch(B("0"), T("a")))},
{"0a", true, 2, false, ``, ``, Seq(Dot, Switch(B("0"), T("a"), B("1"), T("b"), T("c")))},
{"0b", false, 0, false, ``, ``, Seq(Dot, Switch(B("0"), T("a"), B("1"), T("b"), T("c")))},
{"1a", false, 0, false, ``, ``, Seq(Dot, Switch(B("0"), T("a"), B("1"), T("b"), T("c")))},
{"1b", true, 2, false, ``, ``, Seq(Dot, Switch(B("0"), T("a"), B("1"), T("b"), T("c")))},
{"2c", true, 2, false, ``, ``, Seq(Dot, Switch(B("0"), T("a"), B("1"), T("b"), T("c")))},
{"2a", false, 0, false, ``, ``, Seq(Dot, Switch(B("0"), T("a"), B("1"), T("b"), T("c")))},
{"", false, 0, true, ``, ``, Abort("panic")},
{"text", false, 0, true, ``, ``, If(T("^"), Q0(Dot), Abort("text do not starts with '^'"))},
{"^text", true, 5, false, ``, ``, If(T("^"), Q0(Dot), Abort("text do not starts with '^'"))},
}
for _, d := range data {
runPatternTestData(t, d)
}
}
// Tests Count, Until, UntilB, Q0, Q1, Qn, Q01, Qnn, Qmn, J0, Jn, Jnn, Jmn.
func TestQualifierAndJoin(t *testing.T) {
data := []patternTestData{
{"", true, 0, false, ``, ``, Skip(-1)},
{"", true, 0, false, ``, ``, Skip(0)},
{"", false, 0, false, ``, ``, Skip(2)},
{"A", false, 0, false, ``, ``, Skip(2)},
{"AA", true, 2, false, ``, ``, Skip(2)},
{"AAA", true, 2, false, ``, ``, Skip(2)},
{"", false, 0, false, ``, ``, Until(T("."))},
{"A", false, 0, false, ``, ``, Until(T("."))},
{".", true, 0, false, ``, ``, Until(T("."))},
{".B", true, 0, false, ``, ``, Until(T("."))},
{"A.", true, 1, false, ``, ``, Until(T("."))},
{"A.B", true, 1, false, ``, ``, Until(T("."))},
{"AA.", true, 2, false, ``, ``, Until(T("."))},
{"AA.B", true, 2, false, ``, ``, Until(T("."))},
{"", false, 0, false, ``, ``, UntilB(T("."))},
{"A", false, 0, false, ``, ``, UntilB(T("."))},
{".", true, 1, false, ``, ``, UntilB(T("."))},
{".B", true, 1, false, ``, ``, UntilB(T("."))},
{"A.", true, 2, false, ``, ``, UntilB(T("."))},
{"A.B", true, 2, false, ``, ``, UntilB(T("."))},
{"AA.", true, 3, false, ``, ``, UntilB(T("."))},
{"AA.B", true, 3, false, ``, ``, UntilB(T("."))},
{"", true, 0, false, ``, ``, Q0()},
{"", true, 0, false, ``, ``, Q0(T("A"), T("B"))},
{"A", true, 1, false, ``, ``, Q0(T("A"), T("B"))},
{"AB", true, 2, false, ``, ``, Q0(T("A"), T("B"))},
{"", true, 0, false, ``, ``, Q0(T("A"))},
{"A", true, 1, false, ``, ``, Q0(T("A"))},
{"B", true, 0, false, ``, ``, Q0(T("A"))},
{"AA", true, 2, false, ``, ``, Q0(T("A"))},
{"AB", true, 1, false, ``, ``, Q0(T("A"))},
{"", false, 0, false, ``, ``, Q1()},
{"", false, 0, false, ``, ``, Q1(T("A"), T("B"))},
{"A", true, 1, false, ``, ``, Q1(T("A"), T("B"))},
{"BA", true, 2, false, ``, ``, Q1(T("A"), T("B"))},
{"", false, 0, false, ``, ``, Q1(T("A"))},
{"A", true, 1, false, ``, ``, Q1(T("A"))},
{"B", false, 0, false, ``, ``, Q1(T("A"))},
{"AA", true, 2, false, ``, ``, Q1(T("A"))},
{"AB", true, 1, false, ``, ``, Q1(T("A"))},
{"A", true, 1, false, ``, ``, Q1(T("A"))},
{"AAB", true, 2, false, ``, ``, Q1(T("A"))},
{"", true, 0, false, ``, ``, Qn(-1)},
{"", true, 0, false, ``, ``, Qn(0)},
{"", false, 0, false, ``, ``, Qn(1)},
{"", true, 0, false, ``, ``, Qn(0, T("A"), T("B"))},
{"A", true, 1, false, ``, ``, Qn(0, T("A"), T("B"))},
{"BA", true, 2, false, ``, ``, Qn(0, T("A"), T("B"))},
{"", false, 0, false, ``, ``, Qn(1, T("A"), T("B"))},
{"A", true, 1, false, ``, ``, Qn(1, T("A"), T("B"))},
{"BA", true, 2, false, ``, ``, Qn(1, T("A"), T("B"))},
{"", false, 0, false, ``, ``, Qn(2, T("A"))},
{"A", false, 0, false, ``, ``, Qn(2, T("A"))},
{"AB", false, 0, false, ``, ``, Qn(2, T("A"))},
{"AA", true, 2, false, ``, ``, Qn(2, T("A"))},
{"AAB", true, 2, false, ``, ``, Qn(2, T("A"))},
{"AAA", true, 3, false, ``, ``, Qn(2, T("A"))},
{"AAAB", true, 3, false, ``, ``, Qn(2, T("A"))},
{"", true, 0, false, ``, ``, Q01()},
{"", true, 0, false, ``, ``, Q01(T("A"), T("B"))},
{"A", true, 1, false, ``, ``, Q01(T("A"), T("B"))},
{"BA", true, 1, false, ``, ``, Q01(T("A"), T("B"))},
{"", true, 0, false, ``, ``, Q01(T("A"))},
{"A", true, 1, false, ``, ``, Q01(T("A"))},
{"B", true, 0, false, ``, ``, Q01(T("A"))},
{"", true, 0, false, ``, ``, Q0n(-1)},
{"", true, 0, false, ``, ``, Q0n(0)},
{"", true, 0, false, ``, ``, Q0n(1)},
{"", true, 0, false, ``, ``, Q0n(2)},
{"", true, 0, false, ``, ``, Q0n(-1, T("A"))},
{"A", true, 0, false, ``, ``, Q0n(-1, T("A"))},
{"", true, 0, false, ``, ``, Q0n(1, T("A"))},
{"A", true, 1, false, ``, ``, Q0n(1, T("A"))},
{"", true, 0, false, ``, ``, Q0n(2, T("A"), T("B"))},
{"A", true, 1, false, ``, ``, Q0n(2, T("A"), T("B"))},
{"BA", true, 2, false, ``, ``, Q0n(2, T("A"), T("B"))},
{"", true, 0, false, ``, ``, Q0n(2, T("A"))},
{"A", true, 1, false, ``, ``, Q0n(2, T("A"))},
{"AB", true, 1, false, ``, ``, Q0n(2, T("A"))},
{"AA", true, 2, false, ``, ``, Q0n(2, T("A"))},
{"AAB", true, 2, false, ``, ``, Q0n(2, T("A"))},
{"AAA", true, 2, false, ``, ``, Q0n(2, T("A"))},
{"AAAB", true, 2, false, ``, ``, Q0n(2, T("A"))},
{"", true, 0, false, ``, ``, Qnn(-1)},
{"", true, 0, false, ``, ``, Qnn(0)},
{"", false, 0, false, ``, ``, Qnn(1)},
{"", true, 0, false, ``, ``, Qnn(-1, T("A"))},
{"A", true, 0, false, ``, ``, Qnn(-1, T("A"))},
{"", false, 0, false, ``, ``, Qnn(1, T("A"))},
{"A", true, 1, false, ``, ``, Qnn(1, T("A"))},
{"", false, 0, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"A", false, 0, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"B", false, 0, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"AA", true, 2, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"AB", true, 2, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"BA", true, 2, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"BB", true, 2, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"AAB", true, 2, false, ``, ``, Qnn(2, T("A"), T("B"))},
{"", false, 0, false, ``, ``, Qnn(2, T("A"))},
{"A", false, 0, false, ``, ``, Qnn(2, T("A"))},
{"AB", false, 0, false, ``, ``, Qnn(2, T("A"))},
{"AA", true, 2, false, ``, ``, Qnn(2, T("A"))},
{"AAB", true, 2, false, ``, ``, Qnn(2, T("A"))},
{"AAA", true, 2, false, ``, ``, Qnn(2, T("A"))},
{"AAAB", true, 2, false, ``, ``, Qnn(2, T("A"))},
{"", true, 0, false, ``, ``, Qmn(-1, 0)},
{"", true, 0, false, ``, ``, Qmn(0, -1)},
{"", true, 0, false, ``, ``, Qmn(0, 2)},
{"", true, 0, false, ``, ``, Qmn(2, 0)},
{"", false, 0, false, ``, ``, Qmn(1, 2)},
{"", false, 0, false, ``, ``, Qmn(2, 1)},
{"", true, 0, false, ``, ``, Qmn(-1, 0, T("A"))},
{"A", true, 0, false, ``, ``, Qmn(-1, 0, T("A"))},
{"", true, 0, false, ``, ``, Qmn(0, -1, T("A"))},
{"A", true, 0, false, ``, ``, Qmn(0, -1, T("A"))},
{"", false, 0, false, ``, ``, Qmn(2, 1, T("A"))},
{"A", true, 1, false, ``, ``, Qmn(2, 1, T("A"))},
{"AA", true, 2, false, ``, ``, Qmn(2, 1, T("A"))},
{"AAA", true, 2, false, ``, ``, Qmn(2, 1, T("A"))},
{"", false, 0, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"A", true, 1, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"B", true, 1, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"AA", true, 2, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"AB", true, 2, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"BA", true, 2, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"BB", true, 2, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"AAB", true, 2, false, ``, ``, Qmn(1, 2, T("A"), T("B"))},
{"", false, 0, false, ``, ``, Qmn(1, 3, T("A"))},
{"A", true, 1, false, ``, ``, Qmn(1, 3, T("A"))},
{"AB", true, 1, false, ``, ``, Qmn(1, 3, T("A"))},
{"AA", true, 2, false, ``, ``, Qmn(1, 3, T("A"))},
{"AAB", true, 2, false, ``, ``, Qmn(1, 3, T("A"))},
{"AAA", true, 3, false, ``, ``, Qmn(1, 3, T("A"))},
{"AAAB", true, 3, false, ``, ``, Qmn(1, 3, T("A"))},
{"AAAA", true, 3, false, ``, ``, Qmn(1, 3, T("A"))},
{"AAAAB", true, 3, false, ``, ``, Qmn(1, 3, T("A"))},
{"", false, 0, true, ``, ``, Qmn(0, defaultConfig.RepeatLimit+1, True)},
{"", true, 0, false, ``, ``, J0(Q1(R('0', '9')), T("."))},
{"192", true, 3, false, ``, ``, J0(Q1(R('0', '9')), T("."))},
{"192.168.0.1", true, 11, false, ``, ``, J0(Q1(R('0', '9')), T("."))},
{"192.168.0.a", true, 9, false, ``, ``, J0(Q1(R('0', '9')), T("."))},
{"", false, 0, false, ``, ``, J1(Q1(R('0', '9')), T("."))},
{"192", true, 3, false, ``, ``, J1(Q1(R('0', '9')), T("."))},
{"192.168.0.1", true, 11, false, ``, ``, J1(Q1(R('0', '9')), T("."))},
{"192.168.0.a", true, 9, false, ``, ``, J1(Q1(R('0', '9')), T("."))},
{"", true, 0, false, ``, ``, Jn(-1, T("A"), T("-"))},
{"A", true, 1, false, ``, ``, Jn(-1, T("A"), T("-"))},
{"A-", true, 1, false, ``, ``, Jn(-1, T("A"), T("-"))},
{"A-A", true, 3, false, ``, ``, Jn(-1, T("A"), T("-"))},
{"", true, 0, false, ``, ``, Jn(0, T("A"), T("-"))},
{"A", true, 1, false, ``, ``, Jn(0, T("A"), T("-"))},
{"A-", true, 1, false, ``, ``, Jn(0, T("A"), T("-"))},
{"A-A", true, 3, false, ``, ``, Jn(0, T("A"), T("-"))},
{"", false, 0, false, ``, ``, Jn(2, Q1(R('0', '9')), T("."))},
{"1", false, 1, false, ``, ``, Jn(2, Q1(R('0', '9')), T("."))},
{"1.1", true, 3, false, ``, ``, Jn(2, Q1(R('0', '9')), T("."))},
{"1.1.1", true, 5, false, ``, ``, Jn(2, Q1(R('0', '9')), T("."))},
{"1.1.1.1", true, 7, false, ``, ``, Jn(2, Q1(R('0', '9')), T("."))},
{"", true, 0, false, ``, ``, J0n(-1, T("A"), T("-"))},
{"A", true, 0, false, ``, ``, J0n(-1, T("A"), T("-"))},
{"", true, 0, false, ``, ``, J0n(0, T("A"), T("-"))},
{"A", true, 0, false, ``, ``, J0n(0, T("A"), T("-"))},
{"", true, 0, false, ``, ``, J0n(4, Q1(R('0', '9')), T("."))},
{"192", true, 3, false, ``, ``, J0n(4, Q1(R('0', '9')), T("."))},
{"192.168.0.1", true, 11, false, ``, ``, J0n(4, Q1(R('0', '9')), T("."))},
{"192.168.0.1.0", true, 11, false, ``, ``, J0n(4, Q1(R('0', '9')), T("."))},
{"", true, 0, false, ``, ``, Jnn(-1, T("A"), T("-"))},
{"A", true, 0, false, ``, ``, Jnn(-1, T("A"), T("-"))},
{"", true, 0, false, ``, ``, Jnn(0, T("A"), T("-"))},
{"A", true, 0, false, ``, ``, Jnn(0, T("A"), T("-"))},
{"", false, 0, false, ``, ``, Jnn(1, T("A"), T("-"))},
{"A", true, 1, false, ``, ``, Jnn(1, T("A"), T("-"))},
{"192.168", false, 0, false, ``, ``, Jnn(4, Q1(R('0', '9')), T("."))},
{"192.168.0.1", true, 11, false, ``, ``, Jnn(4, Q1(R('0', '9')), T("."))},
{"192.168.0.a", false, 0, false, ``, ``, Jnn(4, Q1(R('0', '9')), T("."))},
{"A", true, 0, false, ``, ``, Jmn(-1, 0, T("A"), T("-"))},
{"A", true, 0, false, ``, ``, Jmn(0, -1, T("A"), T("-"))},
{"", true, 0, false, ``, ``, Jmn(0, 2, T("A"), T("-"))},
{"", true, 0, false, ``, ``, Jmn(2, 0, T("A"), T("-"))},
{"", false, 0, false, ``, ``, Jmn(1, 2, T("A"), T("-"))},
{"", false, 0, false, ``, ``, Jmn(2, 1, T("A"), T("-"))},
{"A", true, 1, false, ``, ``, Jmn(1, 2, T("A"), T("-"))},
{"A", true, 1, false, ``, ``, Jmn(2, 1, T("A"), T("-"))},
{"A-A", true, 3, false, ``, ``, Jmn(1, 2, T("A"), T("-"))},
{"A-A", true, 3, false, ``, ``, Jmn(2, 1, T("A"), T("-"))},
{"", true, 0, false, ``, ``, Jmn(1, 2, Q0(R('0', '9')), T("."))},
{"1", true, 1, false, ``, ``, Jmn(1, 2, Q0(R('0', '9')), T("."))},
{"1.1", true, 3, false, ``, ``, Jmn(1, 2, Q0(R('0', '9')), T("."))},
{"1.1.1", true, 3, false, ``, ``, Jmn(1, 2, Q0(R('0', '9')), T("."))},
{".1", true, 2, false, ``, ``, Jmn(1, 2, Q0(R('0', '9')), T("."))},
{"1.", true, 2, false, ``, ``, Jmn(1, 2, Q0(R('0', '9')), T("."))},
{"1", true, 1, false, ``, ``, Jmn(1, 2, Q0(R('0', '9')), T("."))},
// any Qn(n, pat) where pat could match ""
// will leads to an infinite loop
{"", false, 0, true, ``, ``, Q0(True)},
{"", false, 0, true, ``, ``, Q0(Q0(T("A")))},
{"", false, 0, true, ``, ``, Qn(100, Q01(T("A")))},
{"", false, 0, true, ``, ``, J0(T(""), T(""))},
}
for _, d := range data {
runPatternTestData(t, d)
}
}