forked from NVIDIA/cudf-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegularExpressionTranspilerSuite.scala
More file actions
1469 lines (1286 loc) · 53.9 KB
/
Copy pathRegularExpressionTranspilerSuite.scala
File metadata and controls
1469 lines (1286 loc) · 53.9 KB
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2021-2026, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nvidia.spark.rapids
import java.nio.charset.Charset
import java.util.EnumSet
import java.util.regex.{Pattern, PatternSyntaxException}
import scala.collection.mutable.{HashSet, ListBuffer}
import scala.util.{Random, Try}
import ai.rapids.cudf.{CaptureGroups, ColumnVector, CudfException, RegexFlag, RegexProgram}
import com.nvidia.spark.rapids.Arm.withResource
import com.nvidia.spark.rapids.RegexParser.toReadableString
import org.scalatest.funsuite.AnyFunSuite
import org.apache.spark.sql.rapids.GpuRegExpUtils
import org.apache.spark.sql.types.DataTypes
class RegularExpressionTranspilerSuite extends AnyFunSuite {
test("transpiler detects invalid cuDF patterns that cuDF now supports") {
// these patterns compile in cuDF since https://github.com/rapidsai/cudf/pull/11654 was merged
// but we still reject them because the behavior is not consistent with Java
// The test "AST fuzz test - regexp_replace" hangs if we stop rejecting these patterns
for (pattern <- Seq("\t*|a", "(\t*|a)Dc$1", "\n[^\r\n]x*|^3x")) {
assertUnsupported(pattern, RegexReplaceMode,
"cuDF does not support replace or split with zero-length repetition on one side of a" +
" choice")
}
//The test "AST fuzz test - regexp_find" fails if we stop rejecting these patterns.
for (pattern <- Seq("$|$[^\n]2]}|B")) {
assertUnsupported(pattern, RegexFindMode,
"End of line/string anchor is not supported in this context")
}
}
test("transpiler detects invalid cuDF patterns") {
// The purpose of this test is to document some examples of valid Java regular expressions
// that fail to compile in cuDF and to check that the transpiler detects these correctly.
// Many (but not all) of the patterns here are odd edge cases found during testing with
// random inputs.
val cudfInvalidPatterns = Seq(
"a*+",
"(?d)"
)
// data is not relevant because we are checking for compilation errors
val inputs = Seq("a")
for (pattern <- cudfInvalidPatterns) {
// check that this is valid in Java
Pattern.compile(pattern)
Seq(RegexFindMode, RegexReplaceMode).foreach { mode =>
try {
if (mode == RegexReplaceMode) {
gpuReplace(pattern, REPLACE_STRING, inputs)
} else {
gpuContains(pattern, inputs)
}
fail(s"cuDF unexpectedly compiled expression: $pattern")
} catch {
case e: CudfException =>
// expected, now make sure that the transpiler can detect this
try {
transpile(pattern, mode)
fail(
s"transpiler failed to detect invalid cuDF pattern (mode=$mode): $pattern", e)
} catch {
case _: RegexUnsupportedException =>
// expected
}
}
}
}
}
test("Detect unsupported combinations of line anchors and \\W and \\D") {
val patterns = Seq("\\W\\Z\\D", "\\W$", "$\\D")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"End of line/string anchor is not supported in this context")
)
}
test("choice with repetition - regexp_find") {
val patterns = Seq("b?|a", "b*|^\t", "b+|^\t", "a|b+", "a+|b+", "a{2,3}|b+", "a*|b+",
"b*?|^\t", "b+?|^\t", "a|b+?", "a+?|b+?", "a{2,3}|b+?", "a*?|b+?", "[cat]{3}|dog")
assertCpuGpuMatchesRegexpFind(patterns, Seq("aaa", "bb", "a\tb", "aaaabbbb", "a\tb\ta\tb"))
}
test("choice with repetition - regexp_replace") {
val patterns = Seq("b+|^\t", "a|b+", "a+|b+", "a{2,3}|b+", "[cat]{3}|dog")
assertCpuGpuMatchesRegexpReplace(patterns, Seq("aaa", "bb", "a\tb", "aaaabbbb", "a\tb\ta\tb"))
}
test("zero-length repetition near line anchor - regexp_find") {
val patterns = Seq("\\00*[D$3]$", "\\00*[D$3]\\Z", "^([a-z]*)([0-9]*)([a-z]*)$")
val inputs = Seq("abcd", "abc012abc", "999abb", "\\00D", "D", "D\n", "\\00D\n\r")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
test("zero-length repetition near line anchor - regexp_replace") {
val patterns = Seq("\\00*[D$3]$", "\\00*[D$3]\\Z", "^([a-z]*)([0-9]*)([a-z]*)$")
val inputs = Seq("abcd", "abc012abc", "999abb", "\\00D", "D", "D\n", "\\00D\n\r")
assertCpuGpuMatchesRegexpReplace(patterns, inputs)
}
test("zero-length repetition near line anchor - regexp_split") {
val patterns = Set("\\00*[D$3]$", "\\00*[D$3]\\Z", "^([a-z]*)([0-9]*)([a-z]*)$")
patterns.foreach(pattern => {
assertUnsupported(pattern, RegexSplitMode,
"End of line/string anchor is not supported in this context")
})
}
test("cuDF unsupported choice cases") {
val patterns = Seq("c*|d*", "c*|dog", "c|d?", "c|d{0,2}")
patterns.foreach(pattern => {
assertUnsupported(pattern, RegexReplaceMode,
"cuDF does not support replace or split with zero-length repetition on one side of a"
+ " choice")
})
}
test("newline before $ in replace mode") {
val patterns = Seq("\r$", "\n$", "\r\n$", "\u0085$", "\u2028$", "\u2029$")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexReplaceMode,
"End of line/string anchor is not supported in this context")
)
}
test("cuDF does not support possessive quantifier") {
val patterns = Seq("a*+", "a|(a?|a*+)")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Possessive quantifier *+ not supported")
)
}
test("cuDF does not support \\z") {
assertUnsupported("foo\\z", RegexFindMode,
"\\z is not supported on GPU")
}
test("cuDF does not support positive or negative lookaround") {
val posLookaheadPatterns = Seq("a(?=b)", "a(?=b)c?")
posLookaheadPatterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Positive lookahead groups are not supported")
)
val negLookaheadPatterns = Seq("a(?!b)", "a(?!b)c?")
negLookaheadPatterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Negative lookahead groups are not supported")
)
val posLookbehindPatterns = Seq("a(?<=b)", "a(?<=b)c?")
posLookbehindPatterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Positive lookbehind groups are not supported")
)
val negLookbehindPatterns = Seq("a(?<!b)", "a(?<!b)c?")
negLookbehindPatterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Negative lookbehind groups are not supported")
)
}
test("cuDF does not support quantified lookaround, independent, or named capture groups") {
val quantifiedPatterns =
Seq(raw"a(?>\A)+", raw"a(?=\A)+", raw"a(?!\A)+", raw"a(?<=\A)+", raw"a(?<!\A){2}",
raw"a(?<n>\A){1,}")
quantifiedPatterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Repetition of lookaround, independent, or named capture groups is not supported")
)
}
test("cuDF does not support independent or named capture groups") {
val independentPatterns = Seq("a(?>b)", "a(?>b)c?")
independentPatterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Independent groups are not supported")
)
val namedCapturePatterns = Seq("a(?<name>b)", "a(?<name>b)c?")
namedCapturePatterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Named capture groups are not supported")
)
}
test("cuDF does not support empty sequence") {
val patterns = Seq("", "a|", "()")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode, "Empty sequence not supported")
)
}
test("cuDF does not support $ followed by lookaround, independent, or named groups") {
val patterns =
Seq("$(?=a)", "$(?!a)", "$(?<=a)", "$(?<!a)", "$(?>a)", "$(?<n>a)",
raw"\Z(?=a)", raw"\Z(?>a)")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Regex sequence $ followed by a lookaround, independent, or named capture " +
"group is not supported")
)
}
test("cuDF does not support quantifier syntax when not quantifying anything") {
// note that we could choose to transpile and escape the '{' and '}' characters
val patterns = Seq("{1,2}", "{1,}", "{1}")
patterns.foreach(pattern => {
assertUnsupported(pattern, RegexFindMode,
"Token preceding '{' is not quantifiable near index 0")
}
)
val e = intercept[PatternSyntaxException] {
parse("{2,1}")
}
assert(e.getMessage.contains("Illegal"))
}
test("cuDF does not support single repetition both inside and outside of capture groups") {
val patterns = Seq("(3?)+", "(3?)*", "((3?))+")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support repetition of group containing: 3?"))
Seq("(3*)+").foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support repetition of group containing: 3*"))
}
test("repetition base validation recurses into choices") {
Seq("(3?|a)+", "(a|3?)+").foreach { pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support repetition of group containing: 3?")
}
Seq(
"(3|a)+" -> "(3|a)+",
raw"(a|\d)+" -> "(a|[0-9])+").foreach { case (pattern, expected) =>
assert(transpile(pattern, RegexFindMode) === expected)
}
}
test("cuDF does not support OR at BOL / EOL") {
val patterns = Seq("$|a", "^|a")
patterns.foreach(pattern => {
assertUnsupported(pattern, RegexFindMode,
"Sequences that only contain '^' or '$' are not supported")
})
}
test("cuDF does not support class intersection &&") {
val patterns = Seq("[a&&b]", "[&&1]")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support class intersection operator &&"))
assertCpuGpuMatchesRegexpReplace(Seq("a&&b", "[a&b&c]"), Seq("a&&b", "b&c"))
}
test("octal digits - find") {
val patterns = Seq(raw"\07", raw"\077", raw"\0177", raw"\01772", raw"\0200",
raw"\0376", raw"\0377", raw"\02002")
assertCpuGpuMatchesRegexpFind(patterns, Seq("", "\u0007", "a\u0007b", "a\u007fb",
"\u0007\u003f\u007f", "\u007f", "\u0080", "a\u00fe\u00ffb", "\u007f2"))
}
test("octal digit character classes") {
val patterns = Seq(raw"[\02]", raw"[\012]", raw"[\0177]", raw"[a-\0377]", raw"[\01-\0777]")
val inputs = Seq("", "\u0002", "a\u0012b\n\u0177c", "a[+\u00fe23z")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
test("hex digits - find") {
val patterns = Seq(raw"\x07", raw"\x3f", raw"\x7F", raw"\x7f", raw"\x{7}", raw"\x{0007f}",
raw"\x80", raw"\xff", raw"\x{0008f}", raw"\x{10FFFF}", raw"\x{00eeee}")
assertCpuGpuMatchesRegexpFind(patterns, Seq("", "\u0007", "a\u0007b",
"\u0007\u003f\u007f", "\u0080", "a\u00fe\u00ffb", "ab\ueeeecd"))
}
test("hex digit character classes") {
val patterns = Seq(raw"[\x02]", raw"[\x2c]", raw"[\x7f]", raw"[\x80]", raw"[\x01-\xff]",
raw"[a-\xff]", raw"[\x20-z]")
val inputs = Seq("", "\u007f", "a\u007fb", "\u007f\u003f\u007f", "\u0080", "a\u00fe\u00ffb",
"\u007f2", "abcd", "\u0000\u007f\u00ff\u0123\u0abc")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
test("compare CPU and GPU: character range with escaped characters") {
val inputs = Seq("", "abc", "\r\n", "12\u001b3", "a[b\t\n \rc]d", "[\r+\n-\t[]")
assertCpuGpuMatchesRegexpFind(Seq(raw"[\r\n\t]", raw"[\t-\r]", raw"[\n-\\]", raw"[\a-\e]"),
inputs)
assertCpuGpuMatchesRegexpReplace(Seq("[\t-\r]", "[\b-\t123\n]", "[\\\\u002d-z]"),
inputs)
}
test("string anchors - find") {
val patterns = Seq("\\Atest", "\\A+test", "\\A{1}test", "\\A{1,}test")
assertCpuGpuMatchesRegexpFind(patterns, Seq("", "test", "atest", "testa",
"\ntest", "test\n", "\ntest\n"))
}
test("string anchor on one side of choice") {
val patterns = Seq("a$|b", "^a|b", "\\Aa|b", "a\\Z|\\Ab")
assertCpuGpuMatchesRegexpFind(patterns, Seq("", "testb", "atest", "testa",
"\ntesta", "btesta\n", "\ntestab\n", "testa\r", "btesta\r\n"))
}
test("string anchor on both sides of choice") {
val patterns = Seq("[abcd]$|^abc", "a$|b$", "^a|a$", "^a|b$", "\\Aa|a\\Z", "\\Aa|b\\Z")
assertCpuGpuMatchesRegexpFind(patterns, Seq("", "testb", "atest", "testa",
"\ntesta", "btesta\n", "\ntestab\n", "testa\r", "btesta\r\n"))
}
test("string anchor on either side of choice - regexp_replace") {
val patterns = Seq("a$|b", "^a|b", "\\Aa|b", "a\\Z|\\Ab", "[abcd]$|^abc", "a$|b$", "^a|a$",
"^a|b$", "\\Aa|a\\Z", "\\Aa|b\\Z")
assertCpuGpuMatchesRegexpReplace(patterns, Seq("", "testb", "atest", "testa",
"\ntesta", "btesta\n", "\ntestab\n", "testa\r", "btesta\r\n"))
}
test("string anchor on either side of choice - fallback to CPU - regexp_split") {
val patterns = Set("a$|b", "^a|b", "\\Aa|b", "a\\Z|\\Ab", "[abcd]$|^abc", "a$|b$", "^a|a$",
"^a|b$", "\\Aa|a\\Z", "\\Aa|b\\Z")
patterns.foreach { pattern =>
assertUnsupported(pattern, RegexSplitMode,
"cuDF does not support either side of a choice containing a line anchor in split mode")
}
}
test("string anchor \\A will fall back to CPU in some repetitions") {
val patterns = Seq(raw"(\A)*a", raw"(\A){0,}a", raw"(\A){0}a")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support repetition of group containing: \\A")
)
}
test("string anchor \\Z fall back to CPU in groups") {
val patterns = Seq(raw"(\Z)a", raw"a(\Z)")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Line and string anchors are not supported in capture groups")
)
}
test("string anchor \\Z fall back to CPU in some repetitions") {
val patterns = Seq(raw"a(\Z)+", raw"a(\Z)*", raw"a(\Z){2,}")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support repetition of group containing: \\Z")
)
}
test("string anchor \\Z fall back to CPU - split") {
for (mode <- Seq(RegexSplitMode)) {
assertUnsupported("\\Z", mode,
"Sequences that only contain '^' or '$' are not supported")
}
}
test("line anchors - replace") {
val patterns = Seq("^test", "test$", "^test$", "test\\Z")
assertCpuGpuMatchesRegexpReplace(patterns, Seq("", "test", "atest", "testa",
"\ntest", "test\n", "\ntest\n", "\ntest\r\ntest\n"))
}
test("string anchors - replace") {
val patterns = Seq("\\Atest", "test\\Z")
assertCpuGpuMatchesRegexpReplace(patterns, Seq("", "test", "atest", "testa",
"\ntest", "test\n", "\ntest\n", "\ntest\r\ntest\n"))
}
test("line anchor sequence $\\n fall back to CPU") {
assertUnsupported("a$\n", RegexFindMode,
"End of line/string anchor is not supported in this context")
}
test("issue-14746: anchors inside character classes are literals") {
val patterns = Seq(
"""[$\n]""",
"""[$^]""",
"""[$]\n""",
"""\n[$]""",
"""(?:[$])\n""",
"""[a^]$""",
"""(?:[a^])$""")
val inputs = Seq("", "$", "^", "\n", "$\n", "\n$", "a^", "a^\n", "a\nb")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
assertCpuGpuMatchesRegexpReplace(patterns, inputs)
// Character-class components are alternatives, not a sequence with anchor context.
val characterClass = RegexCharacterClass(
negated = false, ListBuffer(RegexChar('$'), RegexChar('\n')))
val (transpiledClass, _) = new CudfRegexTranspiler(RegexReplaceMode)
.getTranspiledAST(characterClass, None, None)
assert(transpiledClass === characterClass)
// Real anchors outside a class must still detect newlines inside the adjacent class.
Seq("""[\r\n]$""", """$[\r\n]""").foreach { pattern =>
assertUnsupported(pattern, RegexReplaceMode,
"End of line/string anchor is not supported in this context")
}
}
test("line anchor $ - find") {
val patterns = Seq("a$", "a$b", "\f$", "$\f", "TEST$")
val inputs = Seq("a", "a\n", "a\r", "a\r\n", "a\f", "\f", "\r", "\u0085", "\u2028",
"\u2029", "\n", "\r\n", "\r\n\r", "\r\n\u0085", "\n\r",
"\n\u0085", "\n\u2028", "\n\u2029", "2+|+??wD\n", "a\r\nb",
"TEST\u0085\n", "TEST\u0085\r", "TEST\u2028\r","TEST\u2028\u2029", "TEST\u2028\r\n")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
val unsupportedPatterns = Seq("[\r\n]?$", "$\r", "\r$",
// "\u0085$", "\u2028$", "\u2029$", "\n$", "\r\n$", "[D$3]$")
"\u0085$", "\u2028$", "\u2029$", "\n$", "\r\n$")
for (pattern <- unsupportedPatterns) {
assertUnsupported(pattern, RegexFindMode,
"End of line/string anchor is not supported in this context")
}
}
test("string anchor \\Z - find") {
val patterns = Seq("a\\Z", "a\\Zb", "a\\Z+", "\f\\Z", "\\Z\f")
val inputs = Seq("a", "a\n", "a\r", "a\r\n", "a\f", "\f", "\r", "\u0085", "\u2028",
"\u2029", "\n", "\r\n", "\r\n\r", "\r\n\u0085", "\n\r",
"\n\u0085", "\n\u2028", "\n\u2029", "2+|+??wD\n", "a\r\nb")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
val unsupportedPatterns = Seq("[\r\n]?\\Z", "\\Z\r", "\r\\Z",
"\u0085\\Z", "\u2028\\Z", "\u2029\\Z", "\n\\Z", "\r\n\\Z")
for (pattern <- unsupportedPatterns) {
assertUnsupported(pattern, RegexFindMode,
"End of line/string anchor is not supported in this context")
}
}
test("word boundaries around \\D, \\S, \\W, \\H, or \\V - fall back to CPU") {
val patterns = Seq("\\D\\B", "\\W\\B", "\\D\\b", "\\W\\b", "\\S\\b", "\\S\\B", "\\H\\B",
"\\H\\b", "\\V\\B", "\\V\\b")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Word boundaries around \\D, \\S,\\W, \\H, or \\V are not supported")
)
}
test("word boundaries around negated character class - fall back to CPU") {
val patterns = Seq("[^A-Z]\\B", "[^A-Z]\\b")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"Word boundaries around negated character classes are not supported")
)
}
test ("word boundaries will fall back to CPU - split") {
val patterns = Seq("\\b", "\\B")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexSplitMode, "Word boundaries are not supported in split mode")
)
}
test("whitespace boundaries - replace") {
assertCpuGpuMatchesRegexpReplace(
Seq("\\s", "\\S"),
Seq("\u001eTEST"))
}
test("match literal $ - find") {
assertCpuGpuMatchesRegexpFind(
Seq("\\$", "\\$[0-9]"),
Seq("", "$", "$9.99"))
}
test("match literal $ - replace") {
assertCpuGpuMatchesRegexpReplace(
Seq("\\$", "\\$[0-9]"),
Seq("", "$", "$9.99"))
}
test("dot does not match all line terminators") {
// see https://github.com/NVIDIA/spark-rapids/issues/5415
val pattern = Seq("1.")
val inputs = Seq("123", "1\r2", "1\n2", "1\r\n2", "1\u00852", "1\u20282", "1\u20292")
assertCpuGpuMatchesRegexpFind(pattern, inputs)
}
test("dot does not match line terminator combinations") {
val pattern = Seq("a.")
val inputs = Seq("abc", "a\n\rb", "a\n\u0085b", "a\u2029\u0085b", "a\u2082\rb")
assertCpuGpuMatchesRegexpFind(pattern, inputs)
}
test("replace_replace - ?, *, +, and {0, n} repetitions") {
val patterns = Seq("D?", "D*", "D+", "D{0,}", "D{0,1}", "D{0,5}", "[1a-zA-Z]{0,}",
"[1a-zA-Z]{0,2}", "A+")
val inputs = Seq("SS", "DD", "SDSDSDS", "DDDD", "DDDDDD", "ABCDEFG")
assertCpuGpuMatchesRegexpReplace(patterns, inputs)
}
test("dot matches CR on GPU but not on CPU") {
// see https://github.com/rapidsai/cudf/issues/9619
val pattern = "1."
assertCpuGpuMatchesRegexpFind(Seq(pattern), Seq("1\r2", "1\n2", "1\r\n2"))
}
test("character class with ranges") {
val patterns = Seq("[a-b]", "[a-zA-Z]")
patterns.foreach(parse)
}
test("character class mixed") {
val patterns = Seq("[a-b]", "[a+b]", "ab[cFef-g][^cat]")
patterns.foreach(parse)
}
test("transpile character class unescaped range symbol") {
val patterns = Seq("a[-b]", "a[+-]", "a[-+]", "a[-]", "a[^-]")
val expected = Seq(raw"a[\-b]", raw"a[+\-]", raw"a[\-+]", raw"a[\-]", "a(?:[\r]|[^\\-])")
val transpiler = new CudfRegexTranspiler(RegexFindMode)
val transpiled = patterns.map(transpiler.transpile(_, None, None)._1)
assert(transpiled === expected)
}
test("transpile complex regex 2") {
val TIMESTAMP_TRUNCATE_REGEX = "^([0-9]{4}-[0-9]{2}-[0-9]{2} " +
"[0-9]{2}:[0-9]{2}:[0-9]{2})" +
"(.[1-9]*(?:0)?[1-9]+)?(.0*[1-9]+)?(?:.0*)?.\\Z"
// input and output should be identical except for `.` being replaced
// with `[^\n\r\u0085\u2028\u2029]` and `\z` being replaced with `$`
doTranspileTest(TIMESTAMP_TRUNCATE_REGEX,
TIMESTAMP_TRUNCATE_REGEX
.replaceAll("\\.", "[^\n\r\u0085\u2028\u2029]")
.replaceAll("\\\\Z", "\\$"))
}
test("transpile \\A repetitions") {
doTranspileTest("a\\A+", "a\\A")
doTranspileTest("a\\A{1,}", "a\\A")
doTranspileTest("a\\A{2}", "a\\A")
}
test("transpile \\z") {
assertUnsupported("abc\\z", RegexFindMode, "")
}
test("transpile \\Z") {
val expected = "a$"
doTranspileTest("a$", expected)
doTranspileTest("a\\Z", expected)
doTranspileTest("a\\Z+", expected)
doTranspileTest("a\\Z{1}", expected)
doTranspileTest("a\\Z{1,}", expected)
}
test("transpile predefined character classes Lower") {
doTranspileTest("\\p{Lower}", "[a-z]")
}
test("transpile predefined character classes Alpha") {
doTranspileTest("\\p{Alpha}", "[a-zA-Z]")
}
test("transpile predefined character classes Alnum") {
doTranspileTest("\\p{Alnum}", "[a-zA-Z0-9]")
}
test("transpile predefined character classes Punct") {
doTranspileTest("\\p{Punct}", "[!\"#$%&'()*+,\\-./:;<=>?@^_`{|}~\\[\\]\\\\]")
}
test("transpile predefined character classes Print") {
doTranspileTest("\\p{Print}", "[a-zA-Z0-9!\"#$%&'()*+,\\-./:;<=>?@^_`{|}~\\[\\]\\\\\u0020]")
}
test("transpile with group index to extract") {
doTranspileTest("(a)(b)", "(a)(?:b)", 1)
doTranspileTest("(a)(b)", "(?:a)(b)", 2)
doTranspileTest("(a)(b)(c)(d)", "(?:a)(?:b)(?:c)(?:d)", 0)
doTranspileTest("(a)(?:b)(c)", "(a)(?:b)(?:c)", 1)
doTranspileTest("(a)(b)(c)(d)", "(?:a)(?:b)(?:c)(?:d)", 5)
doTranspileTest("(a(b))(c)(d)", "(a(?:b))(?:c)(?:d)", 1)
doTranspileTest("(a(b))(c)(d)", "(?:a(b))(?:c)(?:d)", 2)
doTranspileTest("(ab)+(c)(d)", "(ab)+(?:c)(?:d)", 1)
doTranspileTest("(ab)+(c)(d)", "(?:ab)+(c)(?:d)", 2)
doTranspileTest("([a-z0-9]((([abcd](\\d?)))))", "(?:[a-z0-9](?:((?:[abcd](?:[0-9]?)))))", 3)
doTranspileTest("(a)|(b)", "(?:a)|(b)", 2)
doTranspileTest("(?:(a)(b))", "(?:(?:a)(b))", 2)
doTranspileTest("((a)|(b))", "(?:(?:a)|(b))", 3)
doTranspileTest("(a)(b)|(c)(d)", "(?:a)(?:b)|(c)(?:d)", 3)
doTranspileTest("ab", "ab", 1)
}
test("compare CPU and GPU: character range including unescaped + and -") {
val patterns = Seq("a[-]+", "a[a-b-]+", "a[-a-b]", "a[-+]", "a[+-]")
val inputs = Seq("a+", "a-", "a", "a-+", "a[a-b-]")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
test("compare CPU and GPU: character range including escaped + and - and d") {
val patterns = Seq(raw"a[\-\+]", raw"a[\+\-]", raw"a[a-b\-]", raw"a[\d]", raw"a[\d\+]")
val inputs = Seq("a+", "a-", "a", "a-+", "a[a-b-]", "a0", "a0+")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
test("compare CPU and GPU: octal") {
val patterns = Seq("\\\\141")
val inputs = Seq("a", "b")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
private val REGEXP_LIMITED_CHARS_COMMON = "|()[]{},-./;:!^$#%&*+?<=>@\"'~`_" +
"abc0123x\\ \t\r\n\f\u000b\u0000BsdwSDWZ"
private val REGEXP_LIMITED_CHARS_FIND = REGEXP_LIMITED_CHARS_COMMON
private val REGEXP_LIMITED_CHARS_REPLACE = REGEXP_LIMITED_CHARS_COMMON
test("compare CPU and GPU: find digits") {
val patterns = Seq("\\d", "\\d+", "\\d*", "\\d?")
val inputs = Seq("a", "1", "12", "a12z", "1az2")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
test("compare CPU and GPU: replace digits") {
// note that we do not test with quantifiers `?` or `*` due
// to https://github.com/NVIDIA/spark-rapids/issues/4468
val patterns = Seq("\\d", "\\d+")
val inputs = Seq("a", "1", "12", "a12z", "1az2")
assertCpuGpuMatchesRegexpReplace(patterns, inputs)
}
test("compare CPU and GPU: regexp find fuzz test with limited chars") {
// testing with this limited set of characters finds issues much
// faster than using the full ASCII set
// CR and LF has been excluded due to known issues
doFuzzTest(Some(REGEXP_LIMITED_CHARS_FIND), RegexFindMode)
}
test("compare CPU and GPU: regexp replace simple regular expressions") {
val inputs = Seq("a", "b", "c")
val patterns = Seq("a|b")
assertCpuGpuMatchesRegexpReplace(patterns, inputs)
}
test("compare CPU and GPU: regexp replace line anchor supported use cases") {
val inputs = Seq("a", "b", "c", "cat", "", "^", "$", "^a", "t$")
val patterns = Seq("^a", "^a", "(^a|^t)", "^[ac]", "^^^a", "[\\^^]", "a$", "a$$", "\\$$")
assertCpuGpuMatchesRegexpReplace(patterns, inputs)
}
test("line anchor find - unicode line separators 0085") {
assume(false, "https://github.com/NVIDIA/spark-rapids/issues/7585")
val inputs = Seq("aTEST\u0085", "aTEST\u0085\n", "aTEST\n\u0085")
assertCpuGpuMatchesRegexpFind(Seq("TEST$", "^a|T$"), inputs)
}
test("line anchor find - unicode line separators 2028") {
assume(false, "https://github.com/NVIDIA/spark-rapids/issues/7585")
val inputs = Seq("aTEST\u2028", "aTEST\u2028\n", "aTEST\n\u2028")
assertCpuGpuMatchesRegexpFind(Seq("TEST$", "^a|T$"), inputs)
}
test("line anchor find - unicode line separators 2029") {
assume(false, "https://github.com/NVIDIA/spark-rapids/issues/7585")
val inputs = Seq("aTEST\u2029", "aTEST\u2029\n", "aTEST\n\u2029")
assertCpuGpuMatchesRegexpFind(Seq("TEST$", "^a|T$"), inputs)
}
test("line anchor replace - unicode line separators 0085") {
assume(false, "https://github.com/NVIDIA/spark-rapids/issues/7585")
val inputs = Seq("aTEST\u0085", "aTEST\u0085\n", "aTEST\n\u0085")
assertCpuGpuMatchesRegexpReplace(Seq("TEST$", "^a|T$"), inputs)
}
test("line anchor replace - unicode line separators 2028") {
assume(false, "https://github.com/NVIDIA/spark-rapids/issues/7585")
val inputs = Seq("aTEST\u2028", "aTEST\u2028\n", "aTEST\n\u2028")
assertCpuGpuMatchesRegexpReplace(Seq("TEST$", "^a|T$"), inputs)
}
test("line anchor replace - unicode line separators 2029") {
assume(false, "https://github.com/NVIDIA/spark-rapids/issues/7585")
val inputs = Seq("aTEST\u2029", "aTEST\u2029\n", "aTEST\n\u2029")
assertCpuGpuMatchesRegexpReplace(Seq("TEST$", "^a|T$"), inputs)
}
test("cuDF does not support some uses of line anchors in regexp_replace") {
Seq("^", "$", "^*", "$*", "^+", "$+", "^|$", "^^|$$").foreach(
pattern =>
assertUnsupported(pattern, RegexReplaceMode,
"Sequences that only contain '^' or '$' are not supported")
)
Seq("^$", "(^)($)", "(((^^^)))$").foreach(
pattern =>
assertUnsupported(pattern, RegexReplaceMode,
"End of line/string anchor is not supported in this context")
)
}
test("negated character class newline handling") {
// tests behavior of com.nvidia.spark.rapids.CudfRegexTranspiler.negateCharacterClass
def test(pattern: String, expected: String): Unit = {
val t = new CudfRegexTranspiler(RegexFindMode)
val (actual, _) = t.transpile(pattern, None, None)
assert(toReadableString(expected) === toReadableString(actual))
}
test(raw"[^a]", raw"(?:[\r]|[^a])")
test(raw"[^a\n]", raw"(?:[\r]|[^a\n])")
test(raw"[^a\r]", raw"[^a\r]")
test(raw"[^a\r\n]", raw"[^a\r\n]")
}
test("compare CPU and GPU: regexp replace negated character class") {
val inputs = Seq(
"a", "a\r", "a\n", "a\r\n", "a\n\r",
"b", "b\r", "b\n", "b\r\n", "b\n\r",
"a\nb", "b", "a\r\nb\n\rc\rd", "\r", "\r\n", "\n")
val patterns = Seq(
"[^a]", "[^a\r]", "[^a\n]", "[^a\r\n]",
"[a]", "[a\r]", "[a\n]", "[a\r\n]",
"[^b]", "[^b\r]", "[^b\n]", "[^b\r\n]",
"[^z]", "[^\r]", "[^\n]", "[^\r]",
"[^\r\n]", "[^b\r]", "[^bc\r\n]", "[^\\r\\n]", "[^\r\r]", "[^\r\n\r]", "[^\n\n\r\r]")
assertCpuGpuMatchesRegexpReplace(patterns, inputs)
}
test("compare CPU and GPU: handle escaped brackets") {
val inputs = Seq("[", "]", "[]", "[asdf]", "[deadbeef]", "[a123b456c]")
val patterns = Seq("\\[", "\\]", "\\[]", "\\[\\]", "\\[([a-z]+)\\]", "\\[([a-z0-9]+)\\]")
assertCpuGpuMatchesRegexpFind(patterns, inputs)
}
test("compare CPU and GPU: regexp replace fuzz test with limited chars") {
// testing with this limited set of characters finds issues much
// faster than using the full ASCII set
// LF has been excluded due to known issues
doFuzzTest(Some(REGEXP_LIMITED_CHARS_REPLACE), RegexReplaceMode)
}
test("compare CPU and GPU: regexp find fuzz test printable ASCII chars plus CR, LF, and TAB") {
// CR and LF has been excluded due to known issues
doFuzzTest(Some((0x20 to 0x7F).map(_.toChar) + "\r\n\t"), RegexFindMode)
}
test("compare CPU and GPU: fuzz test ASCII chars") {
// LF has been excluded due to known issues
val chars = (0x00 to 0x7F)
.map(_.toChar)
doFuzzTest(Some(chars.mkString), RegexReplaceMode)
}
test("compare CPU and GPU: regexp find fuzz test all chars") {
// this test cannot be enabled until we support CR and LF
doFuzzTest(None, RegexFindMode)
}
private def doFuzzTest(validChars: Option[String], mode: RegexMode): Unit = {
val r = new EnhancedRandom(new Random(seed = 0L),
options = FuzzerOptions(validChars, maxStringLen = 12))
val data = Range(0, 1000)
.map(_ => r.nextString())
// generate patterns that are valid on both CPU and GPU
val patterns = HashSet[String]()
while (patterns.size < 5000) {
val pattern = r.nextString()
if (!patterns.contains(pattern)) {
if (Try(Pattern.compile(pattern)).isSuccess && Try(transpile(pattern, mode)).isSuccess) {
patterns += pattern
}
}
}
if (mode == RegexReplaceMode) {
assertCpuGpuMatchesRegexpReplace(patterns.toSeq, data)
} else {
assertCpuGpuMatchesRegexpFind(patterns.toSeq, data)
}
}
test("AST fuzz test - regexp_find") {
doAstFuzzTest(Some(REGEXP_LIMITED_CHARS_FIND), REGEXP_LIMITED_CHARS_FIND,
RegexFindMode)
}
test("AST fuzz test - regexp_replace") {
doAstFuzzTest(Some(REGEXP_LIMITED_CHARS_REPLACE), REGEXP_LIMITED_CHARS_REPLACE,
RegexReplaceMode)
}
test("AST fuzz test - regexp_find - full unicode input") {
assume(isUnicodeEnabled())
doAstFuzzTest(None, REGEXP_LIMITED_CHARS_REPLACE,
RegexFindMode)
}
test("AST fuzz test - regexp_replace - full unicode input") {
assume(isUnicodeEnabled())
doAstFuzzTest(None, REGEXP_LIMITED_CHARS_REPLACE,
RegexReplaceMode)
}
def isUnicodeEnabled(): Boolean = {
Charset.defaultCharset().name() == "UTF-8"
}
test("AST fuzz test - regexp_find - anchor focused") {
doAstFuzzTest(validDataChars = Some("\r\nabc"),
validPatternChars = "^$\\AZz\r\n()[]-", mode = RegexFindMode)
}
test("string split - optimized") {
val patterns = Set("\\.", "\\$", "\\[", "\\(", "\\}", "\\+", "\\\\", ",", ";", "cd", "c\\|d",
"\\%", "\\;", "\\/")
val data = Seq("abc.def", "abc$def", "abc[def]", "abc(def)", "abc{def}", "abc+def", "abc\\def",
"abc,def", "abc;def", "abcdef", "abc|def", "abc%def")
for (limit <- Seq(Integer.MIN_VALUE, -2, -1)) {
assertTranspileToSplittableString(patterns)
doStringSplitTest(patterns, data, limit)
}
}
test("string split - not optimized") {
val patterns = Set(".\\$", "\\[.", "\\(.", ".\\}", "\\+.", "c.\\|d")
val data = Seq("abc.$def", "abc$def", "abc[def]", "abc(def)", "abc{def}", "abc+def", "abc\\def",
"abc#|def")
for (limit <- Seq(Integer.MIN_VALUE, -2, -1)) {
assertNoTranspileToSplittableString(patterns)
doStringSplitTest(patterns, data, limit)
}
}
test("issue-14746: string split treats anchors in character classes as literals") {
val patterns = Set(
"""[$\n]""",
"""[$^]""",
"""[$]\n""",
"^a$",
"""\na$""",
"""[\r\n]a$""")
val data = Seq("", "$", "^", "a", "\na", "\r\na", "$\n", "\n$", "a\nb")
doStringSplitTest(patterns, data, -1)
Seq("""[\r\n]$""", """$[\r\n]""").foreach { pattern =>
assertUnsupported(pattern, RegexSplitMode,
"End of line/string anchor is not supported in this context")
}
val optionalPrefixError = intercept[RegexUnsupportedException] {
transpile("a?bc$", RegexSplitMode)
}
assert(optionalPrefixError.getMessage.endsWith("near index 4"),
s"Unexpected split anchor position: ${optionalPrefixError.getMessage}")
}
test("issue-14748: word boundaries are not literal split delimiters") {
assertNoTranspileToSplittableString(Set(raw"\b", raw"\B"))
}
test("regexp_split - character class repetition - ? and *") {
val patterns = Set(raw"[a-z][0-9]?", raw"[a-z][0-9]*")
val data = Seq("a", "aa", "a1a1", "a1b2", "a1b")
for (limit <- Seq(Integer.MIN_VALUE, -2, -1)) {
doStringSplitTest(patterns, data, limit)
}
}
test("regexp_split - character class repetition - ? and * with reluctant quantifier") {
val patterns = Set(raw"[a-z][0-9]??", raw"[a-z][0-9]*?")
val data = Seq("a", "aa", "a1a1", "a1b2", "a1b")
for (limit <- Seq(Integer.MIN_VALUE, -2, -1)) {
doStringSplitTest(patterns, data, limit)
}
}
test("regexp_split - repetition with {0,n}, or {0,}") {
// see https://github.com/NVIDIA/spark-rapids/issues/6958
val patterns = Set("ba{0,}", raw"a\02{0,}", "ba{0,2}", raw"b\02{0,10}")
val data = Seq("abaa", "baba", "ba\u0002b", "ab\u0002b\u0002a")
for (limit <- Seq(Integer.MIN_VALUE, -2, -1)) {
doStringSplitTest(patterns, data, limit)
}
}
test("regexp_split - character class repetition - ? and * - fall back to CPU") {
// see https://github.com/NVIDIA/spark-rapids/issues/6958
val patterns = Seq(raw"[1a-zA-Z]?", raw"[1a-zA-Z]*")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexSplitMode,
"regexp_split on GPU does not support empty match repetition consistently with Spark"
)
)
}
test("regexp_split - character class repetition with choice - ? and * - fall back to CPU") {
val patterns = Seq(raw"c*|d*", raw"c*|dog", raw"a{0,2}|b", raw"b?|a", raw"[cat]{0,3}|dog")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexSplitMode,
"regexp_split on GPU does not support empty match repetition consistently with Spark"
)
)
}
test("regexp_split - fall back to CPU for {0,n}, or {0,}") {
// see https://github.com/NVIDIA/spark-rapids/issues/6958
val patterns = Seq("a{0,}", raw"\02{0,}", "a{0,2}", raw"\02{0,10}")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexSplitMode,
"regexp_split on GPU does not support empty match repetition consistently with Spark"
)
)
}
test("string split - limit < 0") {
val patterns = Set("[^A-Z]+", "[0-9]+", ":", "o", "[:o]")
val data = Seq("abc", "123", "1\n2\n3\n", "boo:and:foo")
for (limit <- Seq(Integer.MIN_VALUE, -2, -1)) {
doStringSplitTest(patterns, data, limit)
}
}
test("string split - limit > 1") {
val patterns = Set("[^A-Z]+", "[0-9]+", ":", "o", "[:o]")
val data = Seq("abc", "123", "1\n2\n3\n", "boo:and:foo")
for (limit <- Seq(2, 5, Integer.MAX_VALUE)) {
doStringSplitTest(patterns, data, limit)
}
}
test("string split fuzz") {
val (data, patterns) = generateDataAndPatterns(Some(REGEXP_LIMITED_CHARS_REPLACE),
REGEXP_LIMITED_CHARS_REPLACE, RegexSplitMode)
for (limit <- Seq(-2, -1, 2, 5)) {
doStringSplitTest(patterns, data, limit)
}
}
// Disabled until https://github.com/NVIDIA/cudf-spark/issues/15293 is fixed
ignore("string split fuzz - anchor focused") {
val (data, patterns) = generateDataAndPatterns(validDataChars = Some("\r\nabc"),
validPatternChars = "^$\\AZz\r\n()", RegexSplitMode)
doStringSplitTest(patterns, data, -1)
}
def assertTranspileToSplittableString(patterns: Set[String]): Unit = {
for (pattern <- patterns) {
val transpiler = new CudfRegexTranspiler(RegexSplitMode)
transpiler.transpileToSplittableString(pattern) match {
case None =>
fail(s"string_split pattern=${toReadableString(pattern)} " +
"does not produce a simplified string to split on"
)
case _ =>
}
}
}
def assertNoTranspileToSplittableString(patterns: Set[String]): Unit = {
for (pattern <- patterns) {
val transpiler = new CudfRegexTranspiler(RegexSplitMode)
transpiler.transpileToSplittableString(pattern) match {
case Some(_) =>
fail(s"string_split pattern=${toReadableString(pattern)} " +
"is trying to produce a simplified string to split on when " +
"it can't"
)
case _ =>
}
}
}
def doStringSplitTest(patterns: Set[String], data: Seq[String], limit: Int): Unit = {
for (pattern <- patterns) {