regexml 0.2.2

XPath compatible regex engine
Documentation
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
// these test cases are a transliteration of test cases in replace.xml
// part of the qt3 test suite

use regexml::{Error, Regex};

// Evaluation of replace function with replacement = "*" as an example 1 for
// this function.
#[test]
fn test_fn_replace_1() {
    let regex = Regex::xpath("bra", "").unwrap();
    let result = regex.replace_all("abracadabra", "*").unwrap();
    assert_eq!(result, "a*cada*");
}

// Evaluation of replace function with pattern = "a.*a" and replacement = "*"
// as an example 2 for this function.
#[test]
fn test_fn_replace_2() {
    let regex = Regex::xpath("a.*a", "").unwrap();
    let result = regex.replace_all("abracadabra", "*").unwrap();
    assert_eq!(result, "*");
}

// Evaluation of replace function with pattern = "a.*?a" and replacement = "*"
// as an example 3 for this function.
#[test]
fn test_fn_replace_3() {
    let regex = Regex::xpath("a.*?a", "").unwrap();
    let result = regex.replace_all("abracadabra", "*").unwrap();
    assert_eq!(result, "*c*bra");
}

// Evaluation of replace function with pattern = "a" and replacement = "" as an
// example 4 for this function.
#[test]
fn test_fn_replace_4() {
    let regex = Regex::xpath("a", "").unwrap();
    let result = regex.replace_all("abracadabra", "").unwrap();
    assert_eq!(result, "brcdbr");
}

// Evaluation of replace function with pattern = "a(.)" and replacement = "a$1$1"
// as an example 5 for this function.
#[test]
fn test_fn_replace_5() {
    let regex = Regex::xpath("a(.)", "").unwrap();
    let result = regex.replace_all("abracadabra", "a$1$1").unwrap();
    assert_eq!(result, "abbraccaddabbra");
}

// Evaluation of replace function with pattern = ".*?" and replacement = "$1" as
// an example 6 for this function. Should raise an error
#[test]
fn test_fn_replace_6() {
    let regex = Regex::xpath(".*?", "").unwrap();
    let err = regex.replace_all("abracadabra", "$1").unwrap_err();
    assert_eq!(err, Error::MatchesEmptyString);
}

// Evaluation of replace function with pattern = "A+" and replacement = "b" as
// an example 7 for this function.
#[test]
fn test_fn_replace_7() {
    let regex = Regex::xpath("A+", "").unwrap();
    let result = regex.replace_all("AAAA", "b").unwrap();
    assert_eq!(result, "b");
}

// Evaluation of replace function with pattern = "A+?" and replacement = "b" as
// an example 8 for this function.
#[test]
fn test_fn_replace_8() {
    let regex = Regex::xpath("A+?", "").unwrap();
    let result = regex.replace_all("AAAA", "b").unwrap();
    assert_eq!(result, "bbbb");
}

// Evaluation of replace function with pattern = "^(.*?)d(.*)" and replacement =
// "$1c$2" as an example 9 for this function.
#[test]
fn test_fn_replace_9() {
    let regex = Regex::xpath("^(.*?)d(.*)$", "").unwrap();
    let result = regex.replace_all("darted", "$1c$2").unwrap();
    assert_eq!(result, "carted");
}

// Evaluation of replace function with pattern = "(ab)|(a)" and replacement =
// "[1=$1][2=$2]" as an example 10 for this function.
#[test]
fn test_fn_replace_10() {
    let regex = Regex::xpath("(ab)|(a)", "").unwrap();
    let result = regex.replace_all("abcd", "[1=$1][2=$2]").unwrap();
    assert_eq!(result, "[1=ab][2=]cd");
}

// Evaluation of replace function with input set to empty sequence.
#[test]
fn test_fn_replace_11() {
    let regex = Regex::xpath("bra", "").unwrap();
    let result = regex.replace_all("", "*").unwrap();
    assert_eq!(result, "");
}

// Evaluation of replace function with pattern set to "\?" for an input string
// that contains "?".
#[test]
fn test_fn_replace_13() {
    let regex = Regex::xpath("\\?", "").unwrap();
    let result = regex
        .replace_all("abracadabra?abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\*" for an input string
// that contains "*".
#[test]
fn test_fn_replace_14() {
    let regex = Regex::xpath("\\*", "").unwrap();
    let result = regex
        .replace_all("abracadabra*abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\+" for an input string
// that contains "+".
#[test]
fn test_fn_replace_15() {
    let regex = Regex::xpath("\\+", "").unwrap();
    let result = regex
        .replace_all("abracadabra+abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\{" for an input string
// that contains "}".
#[test]
fn test_fn_replace_16() {
    let regex = Regex::xpath("\\{", "").unwrap();
    let result = regex
        .replace_all("abracadabra{abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\}" for an input string
// that contains "}".
#[test]
fn test_fn_replace_17() {
    let regex = Regex::xpath("\\}", "").unwrap();
    let result = regex
        .replace_all("abracadabra}abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\(" for an input string
// that contains "(".
#[test]
fn test_fn_replace_18() {
    let regex = Regex::xpath("\\(", "").unwrap();
    let result = regex
        .replace_all("abracadabra(abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\)" for an input string
// that contains ")".
#[test]
fn test_fn_replace_19() {
    let regex = Regex::xpath("\\)", "").unwrap();
    let result = regex
        .replace_all("abracadabra)abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\[" for an input string
// that contains "[".
#[test]
fn test_fn_replace_20() {
    let regex = Regex::xpath("\\[", "").unwrap();
    let result = regex
        .replace_all("abracadabra[abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\]" for an input string
// that contains "]".
#[test]
fn test_fn_replace_21() {
    let regex = Regex::xpath("\\]", "").unwrap();
    let result = regex
        .replace_all("abracadabra]abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\-" for an input string
// that contains "-".
#[test]
fn test_fn_replace_22() {
    let regex = Regex::xpath("\\-", "").unwrap();
    let result = regex
        .replace_all("abracadabra-abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\." for an input string
// that contains ".".
#[test]
fn test_fn_replace_23() {
    let regex = Regex::xpath("\\.", "").unwrap();
    let result = regex
        .replace_all("abracadabra.abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\|" for an input string
// that contains "|".
#[test]
fn test_fn_replace_24() {
    let regex = Regex::xpath("\\|", "").unwrap();
    let result = regex
        .replace_all("abracadabra|abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\\" for an input string
// that contains "\".
#[test]
fn test_fn_replace_25() {
    let regex = Regex::xpath("\\\\", "").unwrap();
    let result = regex
        .replace_all("abracadabra\\abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\t" for an input string
// that contains the tab character.
#[test]
fn test_fn_replace_26() {
    let regex = Regex::xpath("\\t", "").unwrap();
    let result = regex
        .replace_all("abracadabra\tabracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "\n" for an input string
// that contains the newline character.
#[test]
fn test_fn_replace_27() {
    let regex = Regex::xpath("\\n", "").unwrap();
    let result = regex
        .replace_all("abracadabra\nabracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "aa{1}" (exact quantity)
// for an input string that contains the "aa" string.
#[test]
fn test_fn_replace_28() {
    let regex = Regex::xpath("aa{1}", "").unwrap();
    let result = regex.replace_all("abracadabraabracadabra", "with").unwrap();
    assert_eq!(result, "abracadabrwithbracadabra");
}

// Evaluation of replace function with pattern set to "aa{1,}" (min quantity)
// for an input string that contains the "aa" string twice.
#[test]
fn test_fn_replace_29() {
    let regex = Regex::xpath("aa{1,}", "").unwrap();
    let result = regex
        .replace_all("abracadabraabracadabraabracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrwithbracadabrwithbracadabra");
}

// Evaluation of replace function with pattern set to "aa{1,2}" (range quantity)
// for an input string that contains the "aa" string twice.
#[test]
fn test_fn_replace_30() {
    let regex = Regex::xpath("aa{1,2}", "").unwrap();
    let result = regex
        .replace_all("abracadabraabracadabraabracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrwithbracadabrwithbracadabra");
}

// Evaluation of replace function with pattern set to "\^".
#[test]
fn test_fn_replace_31() {
    let regex = Regex::xpath("\\^", "").unwrap();
    let result = regex
        .replace_all("abracadabra^abracadabra", "with")
        .unwrap();
    assert_eq!(result, "abracadabrawithabracadabra");
}

// Evaluation of replace function with pattern set to "^a".
#[test]
fn test_fn_replace_32() {
    let regex = Regex::xpath("^a", "").unwrap();
    let result = regex.replace_all("abracadabra", "with").unwrap();
    assert_eq!(result, "withbracadabra");
}

// Evaluation of replace function with pattern that does not match the input
// string.
#[test]
fn test_fn_replace_33() {
    let regex = Regex::xpath("ww", "").unwrap();
    let result = regex.replace_all("abracadabra", "with").unwrap();
    assert_eq!(result, "abracadabra");
}

// Evaluation of replace function with q flag.
#[test]
fn test_fn_replace_34() {
    let regex = Regex::xpath("a", "q").unwrap();
    let result = regex.replace_all("abracadabra", "$1").unwrap();
    assert_eq!(result, "$1br$1c$1d$1br$1");
}

// Evaluation of replace function with q flag.
#[test]
fn test_fn_replace_35() {
    let regex = Regex::xpath("a?", "q").unwrap();
    let result = regex.replace_all("a?bracadabra?", "\\$1").unwrap();
    assert_eq!(result, "\\$1bracadabr\\$1");
}

// Evaluation of replace function with non-capturing groups.
#[test]
fn test_fn_replace_36() {
    let regex = Regex::xpath("([aA])(?:br)([aA])", "").unwrap();
    let result = regex.replace_all("abracadabra", "$1**$2").unwrap();
    assert_eq!(result, "a**acada**a");
}

// Evaluation of replace function with escaped $ sign in replacement string.
#[test]
fn test_fn_replace_37() {
    let regex = Regex::xpath("a", "").unwrap();
    let result = regex.replace_all("abracadabra", "\\$").unwrap();
    assert_eq!(result, "$br$c$d$br$");
}

// Evaluation of replace function with escaped $ sign in replacement string.
#[test]
fn test_fn_replace_38() {
    let regex = Regex::xpath("(a)", "").unwrap();
    let result = regex.replace_all("abracadabra", "\\$$1").unwrap();
    assert_eq!(result, "$abr$ac$ad$abr$a");
}

// Evaluation of replace function with escaped \ sign in replacement string.
#[test]
fn test_fn_replace_39() {
    let regex = Regex::xpath("a", "").unwrap();
    let result = regex.replace_all("abracadabra", "\\\\").unwrap();
    assert_eq!(result, "\\br\\c\\d\\br\\");
}

// Evaluation of replace with double-digit capture
#[test]
fn test_fn_replace_40() {
    let regex = Regex::xpath("((((( ((((( (((((a))))) ))))) )))))", "x").unwrap();
    let result = regex.replace_all("abracadabra", "|$1$15|").unwrap();
    assert_eq!(result, "|aa|br|aa|c|aa|d|aa|br|aa|");
}

// Evaluation of replace with double-digit capture
#[test]
fn test_fn_replace_41() {
    let regex = Regex::xpath("((((( ((((( (((((a))))) ))))) )))))", "x").unwrap();
    let result = regex.replace_all("abracadabra", "$1520").unwrap();
    assert_eq!(result, "a20bra20ca20da20bra20");
}

// Evaluation of replace with double-digit capture beyond max capture value
#[test]
fn test_fn_replace_42() {
    let regex = Regex::xpath("((((( ((((( (((((a)(b))))) ))))) )))))", "x").unwrap();
    let result = regex
        .replace_all("abracadabra", "($14.$15.$16.$17)")
        .unwrap();
    assert_eq!(result, "(ab.a.b.ab7)racad(ab.a.b.ab7)ra");
}
// "." does NOT match CR in default mode
#[test]
fn test_fn_replace_43() {
    let regex = Regex::xpath("Mary.Jones", "").unwrap();
    let result = regex.replace_all("Mary\rJones", "Jacob Jones").unwrap();
    assert_eq!(result, "Mary\rJones");
}

// "." does match CR in dot-all mode
#[test]
fn test_fn_replace_44() {
    let regex = Regex::xpath("Mary.Jones", "s").unwrap();
    let result = regex.replace_all("Mary\rJones", "Jacob Jones").unwrap();
    assert_eq!(result, "Jacob Jones");
}

// Evaluation of replace, using $0
#[test]
fn test_fn_replace_45() {
    let regex = Regex::xpath("[A-Z][A-Z]+", "").unwrap();
    let result = regex
        .replace_all("Now, let's SEND OUT for QUICHE!!", "$0$0")
        .unwrap();
    assert_eq!(result, "Now, let's SENDSEND OUTOUT for QUICHEQUICHE!!");
}

// Evaluation of replace, Saxon bug 2166
#[test]
fn test_fn_replace_46() {
    let regex = Regex::xpath(r"^\d+(-(\d+))?$", "").unwrap();
    let result = regex.replace_all("12-34", "$2").unwrap();
    assert_eq!(result, "34");
}

// Evaluation of replace, Saxon bug 2390 (reluctant quantifiers, backtracking, and captured groups)
#[test]
fn test_fn_replace_47() {
    let regex = Regex::xpath(r"^.+?(b+)?$", "").unwrap();
    let result = regex.replace_all("abc", "$1").unwrap();
    assert_eq!(result, "");
}

// Evaluation of replace, Saxon bug 2390 (choice, backtracking, and captured groups)
#[test]
fn test_fn_replace_48() {
    let regex = Regex::xpath(r"^a(.).$|^a...$", "").unwrap();
    let result = regex.replace_all("abcd", "$1").unwrap();
    assert_eq!(result, "");
}

// Evaluation of replace function with q flag, with pattern set to "\".
#[test]
fn test_fn_replace_49() {
    let regex = Regex::xpath("/", "q").unwrap();
    let result = regex.replace_all("a/b/c", "\\").unwrap();
    assert_eq!(result, "a\\b\\c");
}

// Evaluation of replace function with q flag, with pattern set to "\\", example
// from spec. (See bug #29522)
#[test]
fn test_fn_replace_50() {
    let regex = Regex::xpath("\\", "q").unwrap();
    let result = regex.replace_all("a\\b\\c", "\\\\").unwrap();
    assert_eq!(result, "a\\\\b\\\\c");
}

// Evaluation of replace function with q flag, with pattern set to "$", example from
// spec. (See bug #29522)
#[test]
fn test_fn_replace_51() {
    let regex = Regex::xpath("/", "q").unwrap();
    let result = regex.replace_all("a/b/c", "$").unwrap();
    assert_eq!(result, "a$b$c");
}

// Evaluation of replace function with q flag, with pattern set to "$'".
#[test]
fn test_fn_replace_52() {
    let regex = Regex::xpath("/", "q").unwrap();
    let result = regex.replace_all("a/b/c", "$'").unwrap();
    assert_eq!(result, "a$'b$'c");
}

// Evaluation of replace function with q flag, with pattern set to "$`". (See bug #29522)
#[test]
fn test_fn_replace_53() {
    let regex = Regex::xpath("/", "q").unwrap();
    let result = regex.replace_all("a/b/c", "$`").unwrap();
    assert_eq!(result, "a$`b$`c");
}

// Evaluation of replace with single-digit capture at end of replacement string. Saxon bug 2735.
#[test]
fn test_fn_replace_54() {
    let regex = Regex::xpath("((((( ((((( (((((a))))) ))))) )))))", "x").unwrap();
    let result = regex.replace_all("abracadabra", "$1$1").unwrap();
    assert_eq!(result, "aabraacaadaabraa");
}

// Test case with undefined captures. Saxon bug 2865.
#[test]
fn test_fn_replace_55() {
    let regex = Regex::xpath("(a)|(b)|(c)|(d)|(e)|(f)|(g)|(h)|(i)|(j)", "").unwrap();
    let result = regex.replace_all("abcdefghijk", "$1").unwrap();
    assert_eq!(result, "ak");
}

// Test case based on Saxon bug 3429.
#[test]
fn test_fn_replace_56() {
    let regex = Regex::xpath(r"^\d*\.?\d+", "").unwrap();
    let result = regex.replace_all("10%", "").unwrap();
    assert_eq!(result, "%");
}

// Evaluation of replace with unmatched double-digit capturing group. Saxon bug 4076.
#[test]
fn test_fn_replace_57() {
    let regex = Regex::xpath("^(9)(8)(7)(6)(5)(4)(3)(2)(1)((A*?)|(.+))$", "").unwrap();
    let result = regex.replace_all("987654321A", "$9$11$12").unwrap();
    assert_eq!(result, "1A");
}

// Evaluation of replace with emoji. Saxon bug 5174.
#[test]
fn test_fn_replace_58() {
    let regex = Regex::xpath(r"\p{IsEmoticons}+", "").unwrap();
    let result = regex.replace_all("Hello 😀😃😄🙆 üäö$", "").unwrap();
    assert_eq!(result, "Hello  üäö$");
}

#[test]
fn test_fn_replace_single_backslash() {
    let regex = Regex::xpath("a", "").unwrap();
    let err = regex.replace_all("abracadabra", "\\").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidReplacementString("Invalid escape at end of replacement string".to_string())
    );
}

// The flags argument cannot contain whitespace.
#[test]
fn test_k_replacefunc_1() {
    let err = Regex::xpath("input", " ").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidFlags("Unrecognized flag ' '".to_string())
    );
}

// The flags argument cannot contain 'X'.
#[test]
fn test_k_replacefunc_2() {
    let err = Regex::xpath("input", "X").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidFlags("Unrecognized flag 'X'".to_string())
    );
}

// A '\' cannot occur at the end of the line.
#[test]
fn test_k_replacefunc_6() {
    let regex = Regex::xpath("in", "").unwrap();
    let err = regex.replace_all("input", "thisIsInvalid\\").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidReplacementString("Invalid escape at end of replacement string".to_string())
    );
}

// A '$' cannot occur at the end of the line.
#[test]
fn test_k_replacefunc_7() {
    let regex = Regex::xpath("(input)", "").unwrap();
    let err = regex.replace_all("input", "thisIsInvalid$").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidReplacementString("Invalid escape at end of replacement string".to_string())
    );
}

// A '\' cannot be used to escape whitespace.
#[test]
fn test_k_replacefunc_8() {
    let regex = Regex::xpath("in", "").unwrap();
    let err = regex.replace_all("input", "thisIsInvalid\\ ").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidReplacementString("Invalid escape ' ' in replacement string".to_string())
    );
}

// A '$' cannot be followed by whitespace.
#[test]
fn test_k_replacefunc_9() {
    let regex = Regex::xpath("in", "").unwrap();
    let err = regex.replace_all("input", "thisIsInvalid$ ").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidReplacementString(
            "$ in replacement string must be followed by a digit".to_string()
        )
    );
}

// Unexpectedly ending escape.
#[test]
fn test_k_replacefunc_10() {
    let regex = Regex::xpath("(a )", "").unwrap();
    let err = regex.replace_all("a a a ", "replacment: \\1").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidReplacementString("Invalid escape '1' in replacement string".to_string())
    );
}

// Unexpected ending escape.
#[test]
fn test_k2_replacefunc_1() {
    let regex = Regex::xpath("(a )", "").unwrap();
    let err = regex.replace_all("a a a ", "replacment: \\1").unwrap_err();
    assert_eq!(
        err,
        Error::InvalidReplacementString("Invalid escape '1' in replacement string".to_string())
    );
}

// Use a back reference inside a character class.
#[test]
fn test_k2_replacefunc_4() {
    let err = Regex::xpath("(asd)[\\1]", "").unwrap_err();
    assert_eq!(
        err,
        Error::Syntax("Backreferences not allowed within character classes".to_string())
    );
}

// Use a back reference inside a character class(#2).
#[test]
fn test_k2_replacefunc_5() {
    let err = Regex::xpath("(asd)[asd\\1]", "").unwrap_err();
    assert_eq!(
        err,
        Error::Syntax("Backreferences not allowed within character classes".to_string())
    );
}

// Use a back reference inside a character class(#3).
#[test]
fn test_k2_replacefunc_6() {
    let err = Regex::xpath("(asd)[asd\\0]", "").unwrap_err();
    assert_eq!(
        err,
        Error::Syntax("Octal escapes are not allowed".to_string())
    );
}

// Use a back reference inside a character class(#3).
#[test]
fn test_k2_replacefunc_7() {
    let err = Regex::xpath("1[asd\\0]", "").unwrap_err();
    assert_eq!(
        err,
        Error::Syntax("Octal escapes are not allowed".to_string())
    );
}

// Tests a prepared expression which matches the empty sequence.
#[test]
fn test_cbcl_fn_replace_002() {
    let regex = Regex::xpath("", "").unwrap();
    let err = regex.replace_all("a", "b").unwrap_err();
    assert_eq!(err, Error::MatchesEmptyString);
}

// Tests empty regex on prepared fn:replace.
#[test]
fn test_cbcl_fn_replace_003() {
    let regex = Regex::xpath("", "").unwrap();
    let err = regex.replace_all("2,4,6,8,10", "c").unwrap_err();
    assert_eq!(err, Error::MatchesEmptyString);
}

// Tests empty regex on prepared fn:replace.
#[test]
fn test_cbcl_fn_replace_004() {
    let regex = Regex::xpath("", "m").unwrap();
    let err = regex.replace_all("2,4,6,8,10", "c").unwrap_err();
    assert_eq!(err, Error::MatchesEmptyString);
}