-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxr-test.el
1203 lines (1146 loc) · 55.5 KB
/
xr-test.el
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
;;; xr-test.el --- Tests for xr.el -*- lexical-binding: t -*-
;; Copyright (C) 2019-2020 Free Software Foundation, Inc.
;; Author: Mattias Engdegård <[email protected]>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(require 'xr)
(require 'ert)
(defmacro xr-test--error (form)
`(condition-case e ,form (error e)))
(ert-deftest xr-basic ()
(should (equal (xr "a\\$b\\\\c\\[\\]\\q")
"a$b\\c[]q"))
(should (equal (xr "\\(?:ab\\|c*d\\)?")
'(opt (or "ab" (seq (zero-or-more "c") "d")))))
(should (equal (xr ".+")
'(one-or-more nonl)))
(should (equal (xr-test--error (xr "$b\\"))
'(xr-parse-error "Backslash at end of regexp" 2 2)))
(let ((text-quoting-style 'grave))
(should (equal (xr-lint "$b\\")
'(((0 0 "Unescaped literal `$'" warning))
((2 2 "Backslash at end of regexp" error)))))
))
(ert-deftest xr-repeat ()
(should (equal (xr "\\(?:x?y\\)\\{3\\}")
'(= 3 (opt "x") "y")))
(should (equal (xr "\\(?:x?y\\)\\{3,8\\}")
'(repeat 3 8 (opt "x") "y")))
(should (equal (xr "\\(?:x?y\\)\\{3,\\}")
'(>= 3 (opt "x") "y")))
(should (equal (xr "\\(?:x?y\\)\\{,8\\}")
'(repeat 0 8 (opt "x") "y")))
(should (equal (xr "\\(?:xy\\)\\{4,4\\}")
'(= 4 "xy")))
(should (equal (xr "a\\{,\\}")
'(zero-or-more "a")))
(should (equal (xr "a\\{0\\}")
'(repeat 0 0 "a")))
(should (equal (xr "a\\{0,\\}")
'(zero-or-more "a")))
(should (equal (xr "a\\{0,0\\}")
'(repeat 0 0 "a")))
(should (equal (xr "a\\{\\}")
'(repeat 0 0 "a")))
(should (equal (xr "a\\{,1\\}")
'(repeat 0 1 "a")))
(should (equal (xr "a\\{1,\\}")
'(>= 1 "a")))
(should (equal (xr-test--error (xr "a\\{3,2\\}"))
'(xr-parse-error "Invalid repetition interval" 3 5)))
(should (equal (xr-test--error (xr "a\\{1,2,3\\}"))
'(xr-parse-error "Missing \\}" 1 5)))
)
(ert-deftest xr-backref ()
(should (equal (xr "\\(ab\\)\\(?3:cd\\)\\1\\3")
'(seq (group "ab") (group-n 3 "cd") (backref 1) (backref 3))))
(should (equal (xr "\\01")
"01"))
(should (equal (xr-test--error (xr "\\(?abc\\)"))
'(xr-parse-error "Invalid \\(? syntax" 0 2)))
(should (equal (xr-test--error (xr "\\(?2\\)"))
'(xr-parse-error "Invalid \\(? syntax" 0 2)))
(should (equal (xr-test--error (xr "\\(?0:xy\\)"))
'(xr-parse-error "Invalid \\(? syntax" 0 2)))
(should (equal (xr "\\(?29:xy\\)")
'(group-n 29 "xy")))
(should (equal (xr-test--error (xr "\\(c?"))
'(xr-parse-error "Missing \\)" 0 3)))
(should (equal (xr-test--error (xr "xy\\)"))
'(xr-parse-error "Unbalanced \\)" 2 3)))
)
(ert-deftest xr-misc ()
(should (equal (xr "^.\\w\\W\\`\\'\\=\\b\\B\\<\\>\\_<\\_>$")
'(seq bol nonl (syntax word) (not (syntax word)) bos eos point
word-boundary not-word-boundary bow eow
symbol-start symbol-end eol)))
(should (equal (xr-test--error (xr "\\_a"))
'(xr-parse-error "Invalid \\_ sequence" 0 2)))
(should (equal (xr "^\\(?:\\(?:\\)\\(?:\\)\\).$")
'(seq bol nonl eol)))
)
(ert-deftest xr-syntax ()
(should (equal (xr "\\s-\\s \\sw\\sW\\s_\\s.\\s(\\s)\\s\"")
'(seq (syntax whitespace) (syntax whitespace) (syntax word)
(syntax word)
(syntax symbol) (syntax punctuation)
(syntax open-parenthesis) (syntax close-parenthesis)
(syntax string-quote))))
(should (equal (xr "\\s\\\\s/\\s$\\s'\\s<\\s>\\s!\\s|")
'(seq (syntax escape) (syntax character-quote)
(syntax paired-delimiter) (syntax expression-prefix)
(syntax comment-start) (syntax comment-end)
(syntax comment-delimiter) (syntax string-delimiter))))
(should (equal (xr "\\S-\\S<")
'(seq (not (syntax whitespace))
(not (syntax comment-start)))))
(should (equal (xr-test--error (xr "\\s"))
'(xr-parse-error "Incomplete \\s sequence" 0 1)))
(should (equal (xr-test--error (xr "\\S"))
'(xr-parse-error "Incomplete \\S sequence" 0 1)))
(let ((text-quoting-style 'grave))
(should (equal (xr-test--error (xr "\\sq"))
'(xr-parse-error "Unknown syntax code `q'" 0 2)))
(should (equal (xr-test--error (xr "\\Sq"))
'(xr-parse-error "Unknown syntax code `q'" 0 2)))
))
(ert-deftest xr-category ()
(should (equal (xr "\\c0\\c1\\c2\\c3\\c4\\c5\\c6\\c7\\c8\\c9\\c<\\c>")
'(seq (category consonant) (category base-vowel)
(category upper-diacritical-mark)
(category lower-diacritical-mark)
(category tone-mark) (category symbol) (category digit)
(category vowel-modifying-diacritical-mark)
(category vowel-sign) (category semivowel-lower)
(category not-at-end-of-line)
(category not-at-beginning-of-line))))
(should (equal (xr "\\cA\\cC\\cG\\cH\\cI\\cK\\cN\\cY\\c^")
'(seq (category alpha-numeric-two-byte) (category chinese-two-byte)
(category greek-two-byte) (category japanese-hiragana-two-byte)
(category indian-two-byte)
(category japanese-katakana-two-byte)
(category korean-hangul-two-byte) (category cyrillic-two-byte)
(category combining-diacritic))))
(should (equal (xr "\\ca\\cb\\cc\\ce\\cg\\ch\\ci\\cj\\ck\\cl\\co\\cq\\cr")
'(seq (category ascii) (category arabic) (category chinese)
(category ethiopic) (category greek) (category korean)
(category indian) (category japanese)
(category japanese-katakana) (category latin) (category lao)
(category tibetan) (category japanese-roman))))
(should (equal (xr "\\ct\\cv\\cw\\cy\\c|")
'(seq (category thai) (category vietnamese) (category hebrew)
(category cyrillic) (category can-break))))
(should (equal (xr "\\C2\\C^")
'(seq (not (category upper-diacritical-mark))
(not (category combining-diacritic)))))
(should (equal (xr "\\cR\\C.\\cL\\C ")
'(seq (category strong-right-to-left)
(not (category base)) (category strong-left-to-right)
(not (category space-for-indent)))))
(should (equal (xr "\\c%\\C+")
'(seq (category ?%) (not (category ?+)))))
(should (equal (xr-test--error (xr "\\c"))
'(xr-parse-error "Incomplete \\c sequence" 0 1)))
(should (equal (xr-test--error (xr "\\C"))
'(xr-parse-error "Incomplete \\C sequence" 0 1)))
)
(ert-deftest xr-lazy ()
(should (equal (xr "\\(?:a.\\)*?")
'(*? "a" nonl)))
(should (equal (xr "\\(?:a.\\)+?")
'(+? "a" nonl)))
(should (equal (xr "\\(?:a.\\)??")
'(?? "a" nonl)))
(should (equal (xr "\\(?:.\\(a+\\(?:b+?c*\\)?\\)??\\)*")
'(zero-or-more
nonl
(?? (group (one-or-more "a")
(opt (+? "b")
(zero-or-more "c")))))))
)
(ert-deftest xr-char-classes ()
(should (equal (xr "[[:alnum:][:blank:]][[:alpha:]][[:cntrl:][:digit:]]")
'(seq (any alnum blank) alpha (any cntrl digit))))
(should (equal (xr "[^[:lower:][:punct:]][^[:space:]]")
'(seq (not (any lower punct)) (not space))))
(should (equal (xr "^[a-z]*")
'(seq bol (zero-or-more (any "a-z")))))
(should (equal (xr "some[.]thing")
"some.thing"))
(should (equal (xr "[^]-c]")
'(not (any "]-c"))))
(should (equal (xr "[-^]")
'(any "^-")))
(should (equal (xr "[a-z-+/*%0-4[:xdigit:]]")
'(any "0-4a-z" "%*+/-" xdigit)))
(should (equal (xr "[^]A-Za-z-]*")
'(zero-or-more (not (any "A-Za-z" "]-")))))
(should (equal (xr "[+*%A-Ka-k0-3${-}]")
'(any "0-3A-Ka-k{-}" "$%*+")))
(should (equal (xr "[^\\\\o][A-\\\\][A-\\\\-a]")
'(seq (not (any "\\o")) (any "A-\\") (any "A-a"))))
(should (equal (xr "[^A-FFGI-LI-Mb-da-eg-ki-ns-tz-v]")
'(not (any "A-FI-Ma-eg-ns-t" "G"))))
(should (equal (xr "[z-a][^z-a]")
'(seq (any) anything)))
(should (equal (xr "[[:alpha]]")
'(seq (any ":[ahlp") "]")))
(should (equal (xr "[:alpha:]")
'(any ":ahlp")))
(should (equal (xr "[[:digit:]-z]")
'(any "z-" digit)))
(should (equal (xr "[A-[:digit:]]")
'(seq (any "A-[" ":dgit") "]")))
(should (equal (xr "[^\n]")
'nonl))
(let ((text-quoting-style 'grave))
(should (equal (xr-test--error (xr "[[::]]"))
'(xr-parse-error "No character class `[::]'" 1 4)))
(should (equal (xr-test--error (xr "[[:=:]]"))
'(xr-parse-error "No character class `[:=:]'" 1 5)))
(should (equal (xr-test--error (xr "[[:letter:]]"))
'(xr-parse-error "No character class `[:letter:]'" 1 10)))
(should (equal (xr-test--error (xr "[a-f"))
'(xr-parse-error "Unterminated character alternative" 0 3)))
)
(should (equal (xr "[aaaaaa][bananabanana][aaaa-cccc][a-ca-ca-c]")
'(seq "a" (any "abn") (any "a-c") (any "a-c"))))
(should (equal (xr "[a-fb-gc-h][a-fc-kh-p]")
'(seq (any "a-h") (any "a-p"))))
)
(ert-deftest xr-empty ()
(should (equal (xr "")
""))
(should (equal (xr "a\\|")
'(or "a" "")))
(should (equal (xr "\\|a")
'(or "" "a")))
(should (equal (xr "a\\|\\|b")
'(or "a" "" "b")))
)
(ert-deftest xr-anything ()
(should (equal (xr "\\(?:.\\|\n\\)?\\(\n\\|.\\)*")
'(seq (opt anything) (zero-or-more (group anything)))))
)
(ert-deftest xr-real ()
(should (equal (xr "\\*\\*\\* EOOH \\*\\*\\*\n")
"*** EOOH ***\n"))
(should (equal (xr "\\<\\(catch\\|finally\\)\\>[^_]")
'(seq bow (group (or "catch" "finally")) eow
(not (any "_")))))
(should (equal (xr "[ \t\n]*:\\([^:]+\\|$\\)")
'(seq (zero-or-more (any "\t\n ")) ":"
(group (or (one-or-more (not (any ":")))
eol)))))
)
(ert-deftest xr-edge-cases ()
(should (equal (xr "^a^b\\(?:^c^\\|^d^\\|e^\\)^")
'(seq bol "a^b" (or (seq bol "c^") (seq bol "d^") "e^") "^")))
(should (equal (xr "$a$b\\(?:$c$\\|$d$\\|$e$\\)$")
'(seq "$a$b" (or (seq "$c" eol) (seq "$d" eol) (seq "$e" eol))
eol)))
(should (equal (xr "*a\\|*b\\(*c\\)")
'(or "*a" (seq "*b" (group "*c")))))
(should (equal (xr "+a\\|+b\\(+c\\)")
'(or "+a" (seq "+b" (group "+c")))))
(should (equal (xr "?a\\|?b\\(^?c\\)")
'(or "?a" (seq "?b" (group bol "?c")))))
(should (equal (xr "^**")
'(seq bol (zero-or-more "*"))))
(should (equal (xr "^+")
'(seq bol "+")))
(should (equal (xr "^?")
'(seq bol "?")))
(should (equal (xr "*?a\\|^??b")
'(or (seq (opt "*") "a") (seq bol (opt "?") "b"))))
(should (equal (xr "^\\{xy")
'(seq bol "{xy")))
(should (equal (xr "\\{2,3\\}")
"{2,3}"))
(should (equal (xr "\\(?:^\\)*")
'(zero-or-more bol)))
(should (equal (xr "\\(?:^\\)\\{3\\}")
'(= 3 bol)))
(should (equal (xr "\\^+")
'(one-or-more "^")))
(should (equal (xr "\\c^?")
'(opt (category combining-diacritic))))
(should (equal (xr "a^*")
'(seq "a" (zero-or-more "^"))))
(should (equal (xr "a^\\{2,7\\}")
'(seq "a" (repeat 2 7 "^"))))
(should (equal (xr "a\\|\\`?b")
'(or "a" (seq bos "?b"))))
(should (equal (xr "a\\|\\`\\{3,4\\}b")
'(or "a" (seq bos "{3,4}b"))))
(should (equal (xr "\\(?:\\`\\)*")
'(zero-or-more bos)))
(should (equal (xr "\\(?:\\`\\)\\{3,4\\}")
'(repeat 3 4 bos)))
)
(ert-deftest xr-simplify ()
(should (equal (xr "a\\(?:b?\\(?:c.\\)d*\\)e")
'(seq "a" (opt "b") "c" nonl (zero-or-more "d") "e")))
(should (equal (xr "a\\(?:b\\(?:c.d\\)e\\)f")
'(seq "abc" nonl "def")))
)
(ert-deftest xr-pretty ()
(should (equal (xr-pp-rx-to-str "A\e\r\n\t\0 \x7f\x80\ B\xff\x02")
"\"A\\e\\r\\n\\t\\x00 \\x7f\\200B\\xff\\x02\"\n"))
(should (equal (xr-pp-rx-to-str '(?? nonl))
"(?? nonl)\n"))
(should (equal (xr-pp-rx-to-str '(? ?\s))
"(? ?\\s)\n"))
(should (equal (xr-pp-rx-to-str '(+? (*? ?*)))
"(+? (*? ?*))\n"))
(should (equal (xr-pp-rx-to-str '(seq "a" ?a ?\s ?\n ?\" ?\\ ?0 ?\0 ?\177))
"(seq \"a\" ?a ?\\s ?\\n ?\\\" ?\\\\ ?0 #x00 #x7f)\n"))
(should (equal (xr-pp-rx-to-str '(category ?Q))
"(category ?Q)\n"))
(should (equal (xr-pp-rx-to-str '(any ?a ?\n ?\( ?\\ ?\200 ?Å ?Ω #x3fff80 32))
"(any ?a ?\\n ?\\( ?\\\\ #x80 ?Å ?Ω #x3fff80 ?\\s)\n"))
(should (equal (xr-pp-rx-to-str '(any (?0 . ?9)))
"(any (?0 . ?9))\n"))
(should (equal (xr-pp-rx-to-str '(repeat 42 ?a))
"(repeat 42 ?a)\n"))
(should (equal (xr-pp-rx-to-str '(repeat 10 13 ?b))
"(repeat 10 13 ?b)\n"))
(should (equal (xr-pp-rx-to-str '(** 9 32 ?c))
"(** 9 32 ?c)\n"))
(should (equal (xr-pp-rx-to-str '(= 3 ?d))
"(= 3 ?d)\n"))
(should (equal (xr-pp-rx-to-str '(>= 8 ?e))
"(>= 8 ?e)\n"))
(should (equal (xr-pp-rx-to-str '(group-n 7 ?f))
"(group-n 7 ?f)\n"))
(should (equal (xr-pp-rx-to-str '(backref 12 ?g))
"(backref 12 ?g)\n"))
(defvar pp-default-function) ; introduced in Emacs 30
(let ((indent-tabs-mode nil)
(pp-default-function 'pp-28))
(should (equal (xr-pp-rx-to-str
'(seq (1+ nonl
(or "a"
(not (any space))))
(* (? (not cntrl)
blank
(| nonascii "abcdef")))))
(concat
"(seq (1+ nonl\n"
" (or \"a\"\n"
" (not (any space))))\n"
" (* (? (not cntrl)\n"
" blank\n"
" (| nonascii \"abcdef\"))))\n")))
(with-temp-buffer
(should (equal (xr-pp ".?\\|b+") nil))
(should (equal (buffer-string)
(concat
"(or (opt nonl)\n"
" (one-or-more \"b\"))\n"))))
(with-temp-buffer
(should (equal (xr-skip-set-pp "^ac-nq\\-u") nil))
(should (equal (buffer-string) "(not (any \"c-n\" \"aqu-\"))\n"))))
)
(ert-deftest xr-dialect ()
(should (equal (xr "a*b+c?d\\{2,5\\}\\(e\\|f\\)[gh][^ij]" 'medium)
'(seq (zero-or-more "a") (one-or-more "b") (opt "c")
(repeat 2 5 "d") (group (or "e" "f"))
(any "gh") (not (any "ij")))))
(should (equal (xr "a*b+c?d\\{2,5\\}\\(e\\|f\\)[gh][^ij]" 'verbose)
'(seq (zero-or-more "a") (one-or-more "b") (zero-or-one "c")
(repeat 2 5 "d") (group (or "e" "f"))
(any "gh") (not (any "ij")))))
(should (equal (xr "a*b+c?d\\{2,5\\}\\(e\\|f\\)[gh][^ij]" 'brief)
'(seq (0+ "a") (1+ "b") (opt "c")
(repeat 2 5 "d") (group (or "e" "f"))
(any "gh") (not (any "ij")))))
(should (equal (xr "a*b+c?d\\{2,5\\}\\(e\\|f\\)[gh][^ij]" 'terse)
'(: (* "a") (+ "b") (? "c")
(** 2 5 "d") (group (| "e" "f"))
(in "gh") (not (in "ij")))))
(should (equal (xr "^\\`\\<.\\>\\'$" 'medium)
'(seq bol bos bow nonl eow eos eol)))
(should (equal (xr "^\\`\\<.\\>\\'$" 'verbose)
'(seq line-start string-start word-start not-newline
word-end string-end line-end)))
(should (equal (xr "^\\`\\<.\\>\\'$" 'brief)
'(seq bol bos bow nonl eow eos eol)))
(should (equal (xr "^\\`\\<.\\>\\'$" 'terse)
'(: bol bos bow nonl eow eos eol)))
(should-error (xr "a" 'asdf))
)
(ert-deftest xr-lint ()
(let ((text-quoting-style 'grave))
(should (equal (xr-lint "^a*\\[\\?\\$\\(b\\{3\\}\\|c\\)$")
nil))
(should (equal (xr-lint "a^b$c")
'(((1 1 "Unescaped literal `^'" warning))
((3 3 "Unescaped literal `$'" warning)))))
(should (equal (xr-lint "^**$")
'(((1 1 "Unescaped literal `*'" warning)))))
(should (equal (xr-lint "a\\|\\`?b")
'(((5 5 "Unescaped literal `?'" warning)))))
(should (equal (xr-lint "a\\|\\`\\{3,4\\}b")
'(((5 6 "Escaped non-special character `{'" warning))
((10 11 "Escaped non-special character `}'" warning)))))
(should (equal (xr-lint "\\{\\(+\\|?\\)\\[\\]\\}\\\t")
'(((0 1 "Escaped non-special character `{'" warning))
((4 4 "Unescaped literal `+'" warning))
((7 7 "Unescaped literal `?'" warning))
((14 15 "Escaped non-special character `}'" warning))
((16 17 "Escaped non-special character `\\t'" warning)))))
(should (equal (xr-lint "\\}\\w\\a\\b\\%")
'(((0 1 "Escaped non-special character `}'" warning))
((4 5 "Escaped non-special character `a'" warning))
((8 9 "Escaped non-special character `%'" warning)))))
(should (equal (xr-lint "a?+b+?\\(?:c*\\)*d\\{3\\}+e*?\\{2,5\\}")
'(((2 2 "Repetition of option" warning)
(0 1 "This is the inner expression" info))
((14 14 "Repetition of repetition" warning)
(6 13 "This is the inner expression" info))
((25 31 "Repetition of repetition" warning)
(22 24 "This is the inner expression" info)))))
(should (equal (xr-lint "\\(?:a+\\)?")
nil))
(should (equal (xr-lint "\\(a*\\)*\\(b+\\)*\\(c*\\)?\\(d+\\)?")
'(((6 6 "Repetition of repetition" warning)
(0 5 "This is the inner expression" info))
((13 13 "Repetition of repetition" warning)
(7 12 "This is the inner expression" info))
((20 20 "Optional repetition" warning)
(14 19 "This is the inner expression" info)))))
(should (equal (xr-lint "\\(a?\\)+\\(b?\\)?")
'(((6 6 "Repetition of option" warning)
(0 5 "This is the inner expression" info))
((13 13 "Optional option" warning)
(7 12 "This is the inner expression" info)))))
(should (equal (xr-lint "\\(e*\\)\\{3\\}")
'(((6 10 "Repetition of repetition" warning)
(0 5 "This is the inner expression" info)))))
(should (equal (xr-lint "\\(a?\\)\\{4,7\\}")
'(((6 12 "Repetition of option" warning)
(0 5 "This is the inner expression" info)))))
(should (equal (xr-lint "\\(?:a?b+c?d*\\)*")
'(((14 14 "Repetition of effective repetition" warning)
(0 13 "This expression contains a repetition" info)))))
(should (equal (xr-lint "\\(a?b+c?d*\\)*")
'(((12 12 "Repetition of effective repetition" warning)
(0 11 "This expression contains a repetition" info)))))
(should (equal (xr-lint "a*\\|b+\\|\\(?:a\\)*")
'(((8 15 "Duplicated alternative branch" warning)
(0 1 "Previous occurrence here" info)))))
(should (equal (xr-lint "a\\{,\\}")
'(((1 5 "Uncounted repetition" warning)))))
(should (equal (xr-lint "a\\{\\}")
'(((1 4 "Implicit zero repetition" warning)))))
(should (equal (xr-lint "\\'*\\<?\\(?:$\\)+")
'(((2 2 "Repetition of zero-width assertion" warning)
(0 1 "Zero-width assertion here" info))
((5 5 "Optional zero-width assertion" warning)
(3 4 "Zero-width assertion here" info))
((13 13 "Repetition of zero-width assertion" warning)
(6 12 "Zero-width assertion here" info)))))
(should
(equal
(xr-lint "\\b\\{2\\}\\(a\\|\\|b\\)\\{,8\\}")
'(((2 6 "Repetition of zero-width assertion" warning)
(0 1 "Zero-width assertion here" info))
((17 22 "Repetition of expression matching an empty string" warning)
(7 16 "This expression matches an empty string" info)))))
(should (equal (xr-lint "\\(?:\\`\\)*")
'(((8 8 "Repetition of zero-width assertion" warning)
(0 7 "Zero-width assertion here" info)))))
(should (equal (xr-lint "\\(?:\\`\\)\\{3,4\\}")
'(((8 14 "Repetition of zero-width assertion" warning)
(0 7 "Zero-width assertion here" info)))))
))
(ert-deftest xr-lint-char-alt ()
(let ((text-quoting-style 'grave))
(should (equal (xr-lint "[^]\\a-d^-]")
nil))
(should
(equal (xr-lint "a[\\\\[]b[d-g.d-g]c")
'(((3 3 "Duplicated `\\' inside character alternative" warning)
(2 2 "Previous occurrence here" info))
((12 14 "Duplicated `d-g' inside character alternative" warning)
(8 10 "Previous occurrence here" info)))))
(should (equal (xr-lint "[]-Qa-fz-t]")
'(((1 3 "Reversed range `]-Q' matches nothing" warning))
((7 9 "Reversed range `z-t' matches nothing" warning)))))
(should (equal (xr-lint "[z-a][^z-a]")
nil))
(should (equal (xr-lint "[^A-FFGI-LI-Mb-da-eg-ki-ns-t33-7]")
'(((5 5 "Character `F' included in range `A-F'" warning)
(2 4 "Previous occurrence here" info))
((10 12 "Ranges `I-L' and `I-M' overlap" warning)
(7 9 "Previous occurrence here" info))
((16 18 "Ranges `a-e' and `b-d' overlap" warning)
(13 15 "Previous occurrence here" info))
((22 24 "Ranges `g-k' and `i-n' overlap" warning)
(19 21 "Previous occurrence here" info))
((25 27 "Two-character range `s-t'" warning))
((29 31 "Range `3-7' includes character `3'" warning)
(28 28 "Previous occurrence here" info)))))
(should (equal (xr-lint "[a[:digit:]b[:punct:]c[:digit:]]")
'(((22 30 "Duplicated character class `[:digit:]'" warning)
(2 10 "Previous occurrence here" info)))))
(should (equal (xr-lint "[0-9[|]*/]")
'(((4 4 "Suspect `[' in char alternative" warning)))))
(should (equal (xr-lint "[^][-].]")
nil))
(should (equal (xr-lint "\\[\\([^\\[]*\\)\\]$")
nil))
(should (equal (xr-lint "[0-1]")
nil))
(should (equal (xr-lint "[^]-][]-^]")
'(((6 8 "Two-character range `]-^'" warning)))))
(should
(equal
(xr-lint "[-A-Z][A-Z-][A-Z-a][^-A-Z][]-a][A-Z---.]")
'(((16 16
"Literal `-' not first or last in character alternative" warning)))))
;; The range "[\x70-\x8f]" only includes 70..7f and 3fff80..3fff8f;
;; the gap 80..3fff7f is excluded.
(should (equal (xr-lint "[\x70-\x8f∃]") nil))
(should (equal (xr-lint "[\x70-\x8f\x7e-å]")
'(((4 6 "Ranges `\x70-\\x7f' and `\x7e-å' overlap" warning)
(1 3 "Previous occurrence here" info)))))
(should
(equal (xr-lint "[\x70-\x8få-\x82]")
'(((4 6 "Ranges `å-\\x82' and `\\x80-\\x8f' overlap" warning)
(1 3 "Previous occurrence here" info)))))
(should
(equal (xr-lint "[A-z]")
'(((1 3 "Range `A-z' between upper and lower case includes symbols"
warning)))))
))
(ert-deftest xr-lint-noisy ()
(should-error (xr-lint "." nil 'bad))
(let ((text-quoting-style 'grave))
(dolist (checks '(nil all))
(ert-info ((prin1-to-string checks) :prefix "checks: ")
(should
(equal
(xr-lint "[0-9+-/*][&-+=]" nil checks)
(if (eq checks 'all)
'(((4 6 "Suspect character range `+-/': should `-' be literal?"
warning))
((10 12 "Suspect character range `&-+': should `-' be literal?"
warning)))
nil)))
(should
(equal
(xr-lint "[ \\t][-.\\d][\\Sw][\\rnt]" nil checks)
(if (eq checks 'all)
'(((2 3 "Possibly erroneous `\\t' in character alternative"
warning))
((8 9 "Possibly erroneous `\\d' in character alternative"
warning))
((12 13 "Possibly erroneous `\\S' in character alternative"
warning))))))
(should (equal (xr-lint "\\(?:ta\\)\\(:?da\\)\\(:?\\)" nil checks)
(if (eq checks 'all)
'(((10 11 "Possibly mistyped `:?' at start of group"
warning)))
nil)))
(should
(equal
(xr-lint "%\\|[abc]\\|[[:digit:]]\\|\\s-\\|\\s_"
nil checks)
(if (eq checks 'all)
'(((0 7 "Or-pattern more efficiently expressed as character alternative" warning))
((3 20 "Or-pattern more efficiently expressed as character alternative" warning))
((10 25 "Or-pattern more efficiently expressed as character alternative" warning)))
nil)))
))))
(ert-deftest xr-lint-repetition-of-empty ()
(let ((text-quoting-style 'grave))
(should
(equal
(xr-lint "\\(?:a*b?\\)*\\(c\\|d\\|\\)+\\(^\\|e\\)*\\(?:\\)*")
'(((10 10 "Repetition of expression matching an empty string" warning)
(0 9 "This expression matches an empty string" info))
((21 21 "Repetition of expression matching an empty string" warning)
(11 20 "This expression matches an empty string" info)))))
(should
(equal
(xr-lint "\\(?:a*?b??\\)+?")
'(((12 13 "Repetition of expression matching an empty string" warning)
(0 11 "This expression matches an empty string" info)))))
(should
(equal (xr-lint "\\(?:a*b?\\)?")
'(((10 10 "Optional expression matching an empty string" warning)
(0 9 "This expression matches an empty string" info)))))))
(ert-deftest xr-lint-branch-subsumption ()
(let ((text-quoting-style 'grave))
(should
(equal (xr-lint "a.cde*f?g\\|g\\|abcdefg")
'(((14 20 "Branch matches subset of a previous branch" warning)
(0 8 "This is the superset branch" info)))))
(should
(equal (xr-lint "abcd\\|e\\|[aA].[^0-9z]d")
'(((9 21 "Branch matches superset of a previous branch" warning)
(0 3 "This is the subset branch" info)))))
(should
(equal (xr-lint "\\(?:\\(a\\)\\|.\\)\\(?:a\\|\\(.\\)\\)")
'(((21 25 "Branch matches superset of a previous branch" warning)
(18 18 "This is the subset branch" info)))))
(should
(equal (xr-lint ".\\|\n\\|\r")
'(((6 6 "Branch matches subset of a previous branch" warning)
(0 0 "This is the superset branch" info)))))
(should
(equal (xr-lint "[^mM]\\|[^a-zA-Z]")
'(((7 15 "Branch matches subset of a previous branch" warning)
(0 4 "This is the superset branch" info)))))
(should (equal (xr-lint "[^mM]\\|[^A-LN-Z]")
nil))
(should (equal (xr-lint "[ab]\\|[^bcd]")
nil))
(should
(equal (xr-lint "[ab]\\|[^cd]")
'(((6 10 "Branch matches superset of a previous branch" warning)
(0 3 "This is the subset branch" info)))))
(should (equal (xr-lint ".\\|[a\n]")
nil))
(should
(equal (xr-lint "ab?c+\\|a?b*c*")
'(((7 12 "Branch matches superset of a previous branch" warning)
(0 4 "This is the subset branch" info)))))
(should
(equal (xr-lint "\\(?:[aA]\\|b\\)\\|a")
'(((15 15 "Branch matches subset of a previous branch" warning)
(0 12 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\(?:a\\|b\\)\\|[abc]")
'(((12 16 "Branch matches superset of a previous branch" warning)
(0 9 "This is the subset branch" info)))))
(should
(equal (xr-lint "\\(?:a\\|b\\)\\|\\(?:[abd]\\|[abc]\\)")
'(((12 29 "Branch matches superset of a previous branch" warning)
(0 9 "This is the subset branch" info)))))
(should
(equal (xr-lint "ab\\|abc?")
'(((4 7 "Branch matches superset of a previous branch" warning)
(0 1 "This is the subset branch" info)))))
(should
(equal (xr-lint "abc\\|abcd*e?")
'(((5 11 "Branch matches superset of a previous branch" warning)
(0 2 "This is the subset branch" info)))))
(should (equal (xr-lint "[a[:digit:]]\\|[a\n]")
nil))
(should
(equal (xr-lint "[a[:ascii:]]\\|[a\n]")
'(((14 17 "Branch matches subset of a previous branch" warning)
(0 11 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:alnum:]]\\|[[:alpha:]]")
'(((13 23 "Branch matches subset of a previous branch" warning)
(0 10 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:alnum:]%]\\|[[:alpha:]%]")
'(((14 25 "Branch matches subset of a previous branch" warning)
(0 11 "This is the superset branch" info)))))
(should (equal (xr-lint "[[:xdigit:]%]\\|[[:alpha:]%]")
nil))
(should (equal (xr-lint "[[:alnum:]]\\|[^[:alpha:]]")
nil))
(should (equal (xr-lint "[^[:alnum:]]\\|[[:alpha:]]")
nil))
(should
(equal (xr-lint "[[:digit:]]\\|[^[:punct:]]")
'(((13 24 "Branch matches superset of a previous branch" warning)
(0 10 "This is the subset branch" info)))))
(should
(equal (xr-lint "[^[:digit:]]\\|[[:punct:]]")
'(((14 24 "Branch matches subset of a previous branch" warning)
(0 11 "This is the superset branch" info)))))
(should
(equal (xr-lint "[^[:digit:]]\\|[^[:xdigit:]]")
'(((14 26 "Branch matches subset of a previous branch" warning)
(0 11 "This is the superset branch" info)))))
(should (equal (xr-lint "[^[:print:]]\\|[[:ascii:]]")
nil))
(should (equal (xr-lint "[[:print:]]\\|[^[:ascii:]]")
nil))
(should (equal (xr-lint "[^[:print:]]\\|[^[:ascii:]]")
nil))
(should
(equal (xr-lint "[[:digit:][:cntrl:]]\\|[[:ascii:]]")
'(((22 32 "Branch matches superset of a previous branch" warning)
(0 19 "This is the subset branch" info)))))
(should
(equal (xr-lint "[[:alpha:]]\\|A")
'(((13 13 "Branch matches subset of a previous branch" warning)
(0 10 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:alpha:]]\\|[A-E]")
'(((13 17 "Branch matches subset of a previous branch" warning)
(0 10 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:alpha:]3-7]\\|[A-E46]")
'(((16 22 "Branch matches subset of a previous branch" warning)
(0 13 "This is the superset branch" info)))))
(should
(equal (xr-lint "[^[:alpha:]]\\|[123]")
'(((14 18 "Branch matches subset of a previous branch" warning)
(0 11 "This is the superset branch" info)))))
(should
(equal (xr-lint "[!-@]\\|[[:digit:]]")
'(((7 17 "Branch matches subset of a previous branch" warning)
(0 4 "This is the superset branch" info)))))
(should
(equal (xr-lint "[^a-z]\\|[[:digit:]]")
'(((8 18 "Branch matches subset of a previous branch" warning)
(0 5 "This is the superset branch" info)))))
(should
(equal (xr-lint "[^[:punct:]]\\|[a-z]")
'(((14 18 "Branch matches subset of a previous branch" warning)
(0 11 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:space:]]\\|[ \t\f]")
'(((13 17 "Branch matches subset of a previous branch" warning)
(0 10 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:word:]]\\|[a-gH-P2357]")
'(((12 23 "Branch matches subset of a previous branch" warning)
(0 9 "This is the superset branch" info)))))
(should
(equal (xr-lint "[^[:space:]]\\|[a-gH-P2357]")
'(((14 25 "Branch matches subset of a previous branch" warning)
(0 11 "This is the superset branch" info)))))
(should
(equal (xr-lint "[^z-a]\\|[^0-9[:space:]]")
'(((8 22 "Branch matches subset of a previous branch" warning)
(0 5 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\(?:.\\|\n\\)\\|a")
'(((12 12 "Branch matches subset of a previous branch" warning)
(0 9 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\s-\\| ")
'(((5 5 "Branch matches subset of a previous branch" warning)
(0 2 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\S-\\|x")
'(((5 5 "Branch matches subset of a previous branch" warning)
(0 2 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\cl\\|å")
'(((5 5 "Branch matches subset of a previous branch" warning)
(0 2 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\Ca\\|ü")
'(((5 5 "Branch matches subset of a previous branch" warning)
(0 2 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\w\\|[^z-a]")
'(((4 9 "Branch matches superset of a previous branch" warning)
(0 1 "This is the subset branch" info)))))
(should
(equal (xr-lint "\\W\\|[^z-a]")
'(((4 9 "Branch matches superset of a previous branch" warning)
(0 1 "This is the subset branch" info)))))
(should
(equal (xr-lint "\\w\\|a")
'(((4 4 "Branch matches subset of a previous branch" warning)
(0 1 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\W\\|\f")
'(((4 4 "Branch matches subset of a previous branch" warning)
(0 1 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:punct:]]\\|!")
'(((13 13 "Branch matches subset of a previous branch" warning)
(0 10 "This is the superset branch" info)))))
(should
(equal (xr-lint "[[:ascii:]]\\|[^α-ω]")
'(((13 18 "Branch matches superset of a previous branch" warning)
(0 10 "This is the subset branch" info)))))
(should
(equal (xr-lint "[^a-f]\\|[h-z]")
'(((8 12 "Branch matches subset of a previous branch" warning)
(0 5 "This is the superset branch" info)))))
(should
(equal (xr-lint "[0-9]\\|\\S(")
'(((7 9 "Branch matches superset of a previous branch" warning)
(0 4 "This is the subset branch" info)))))
(should
(equal (xr-lint "a+\\|[ab]+")
'(((4 8 "Branch matches superset of a previous branch" warning)
(0 1 "This is the subset branch" info)))))
(should
(equal (xr-lint "[ab]?\\|a?")
'(((7 8 "Branch matches subset of a previous branch" warning)
(0 4 "This is the superset branch" info)))))
(should
(equal (xr-lint "a*\\|")
'(((4 nil "Branch matches subset of a previous branch" warning)
(0 1 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\|a*")
'(((2 3 "Branch matches superset of a previous branch" warning)
(0 nil "This is the subset branch" info)))))
(should
(equal (xr-lint "a?\\|")
'(((4 nil "Branch matches subset of a previous branch" warning)
(0 1 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\|a?")
'(((2 3 "Branch matches superset of a previous branch" warning)
(0 nil "This is the subset branch" info)))))
(should
(equal (xr-lint "a*?\\|")
'(((5 nil "Branch matches subset of a previous branch" warning)
(0 2 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\|a*?")
'(((2 4 "Branch matches superset of a previous branch" warning)
(0 nil "This is the subset branch" info)))))
(should
(equal (xr-lint "a??\\|")
'(((5 nil "Branch matches subset of a previous branch" warning)
(0 2 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\|a??")
'(((2 4 "Branch matches superset of a previous branch" warning)
(0 nil "This is the subset branch" info)))))
(should
(equal (xr-lint "a\\{0,4\\}\\|")
'(((10 nil "Branch matches subset of a previous branch" warning)
(0 7 "This is the superset branch" info)))))
(should
(equal (xr-lint "\\|a\\{0,4\\}")
'(((2 9 "Branch matches superset of a previous branch" warning)
(0 nil "This is the subset branch" info)))))
))
(ert-deftest xr-lint-subsumed-repetition ()
(let ((text-quoting-style 'grave))
(should
(equal (xr-lint "\\(?:a.c\\|def\\)+\\(?:abc\\)*")
'(((15 24 "Repetition subsumed by preceding repetition" warning)
(0 14 "Subsuming repetition here" info)))))
;; Exhaustive test of all possible combinations.
(should
(equal (xr-lint "[ab]+a?,a?[ab]+,[ab]+a*,a*[ab]+")
'(((5 6 "Repetition subsumed by preceding repetition" warning)
(0 4 "Subsuming repetition here" info))
((10 14 "Repetition subsumes preceding repetition" warning)
(8 9 "Subsumed repetition here" info))
((21 22 "Repetition subsumed by preceding repetition" warning)
(16 20 "Subsuming repetition here" info))
((26 30 "Repetition subsumes preceding repetition" warning)
(24 25 "Subsumed repetition here" info)))))
(should
(equal (xr-lint "[ab]*a?,a?[ab]*,[ab]*a*,a*[ab]*")
'(((5 6 "Repetition subsumed by preceding repetition" warning)
(0 4 "Subsuming repetition here" info))
((10 14 "Repetition subsumes preceding repetition" warning)
(8 9 "Subsumed repetition here" info))
((21 22 "Repetition subsumed by preceding repetition" warning)
(16 20 "Subsuming repetition here" info))
((26 30 "Repetition subsumes preceding repetition" warning)
(24 25 "Subsumed repetition here" info)))))
(should
(equal (xr-lint "a+a?,a?a+,a+a*,a*a+,a*a?,a?a*,a*a*")
'(((2 3 "Repetition subsumed by preceding repetition" warning)
(0 1 "Subsuming repetition here" info))
((7 8 "Repetition subsumes preceding repetition" warning)
(5 6 "Subsumed repetition here" info))
((12 13 "Repetition subsumed by preceding repetition" warning)
(10 11 "Subsuming repetition here" info))
((17 18 "Repetition subsumes preceding repetition" warning)
(15 16 "Subsumed repetition here" info))
((22 23 "Repetition subsumed by preceding repetition" warning)
(20 21 "Subsuming repetition here" info))
((27 28 "Repetition subsumes preceding repetition" warning)
(25 26 "Subsumed repetition here" info))
((32 33 "Repetition subsumed by preceding repetition" warning)
(30 31 "Subsuming repetition here" info)))))
(should
(equal (xr-lint "[ab]+a??,a??[ab]+,[ab]+a*?,a*?[ab]+")
'(((5 7 "Repetition subsumed by preceding repetition" warning)
(0 4 "Subsuming repetition here" info))
((12 16 "Repetition subsumes preceding repetition" warning)
(9 11 "Subsumed repetition here" info))
((23 25 "Repetition subsumed by preceding repetition" warning)
(18 22 "Subsuming repetition here" info))
((30 34 "Repetition subsumes preceding repetition" warning)
(27 29 "Subsumed repetition here" info)))))
(should
(equal (xr-lint "[ab]*a??,a??[ab]*,[ab]*a*?,a*?[ab]*")
'(((5 7 "Repetition subsumed by preceding repetition" warning)
(0 4 "Subsuming repetition here" info))
((12 16 "Repetition subsumes preceding repetition" warning)
(9 11 "Subsumed repetition here" info))
((23 25 "Repetition subsumed by preceding repetition" warning)
(18 22 "Subsuming repetition here" info))
((30 34 "Repetition subsumes preceding repetition" warning)
(27 29 "Subsumed repetition here" info)))))
(should
(equal (xr-lint "a+a??,a??a+,a+a*?,a*?a+,a*a??,a??a*,a*a*?,a*?a*")
'(((2 4 "Repetition subsumed by preceding repetition" warning)
(0 1 "Subsuming repetition here" info))
((9 10 "Repetition subsumes preceding repetition" warning)
(6 8 "Subsumed repetition here" info))
((14 16 "Repetition subsumed by preceding repetition" warning)
(12 13 "Subsuming repetition here" info))
((21 22 "Repetition subsumes preceding repetition" warning)
(18 20 "Subsumed repetition here" info))
((26 28 "Repetition subsumed by preceding repetition" warning)
(24 25 "Subsuming repetition here" info))
((33 34 "Repetition subsumes preceding repetition" warning)
(30 32 "Subsumed repetition here" info))
((38 40 "Repetition subsumed by preceding repetition" warning)
(36 37 "Subsuming repetition here" info))
((45 46 "Repetition subsumes preceding repetition" warning)
(42 44 "Subsumed repetition here" info)))))
(should (equal (xr-lint "[ab]+?a?,a?[ab]+?,[ab]+?a*,a*[ab]+?")
nil))
(should (equal (xr-lint "[ab]*?a?,a?[ab]*?,[ab]*?a*,a*[ab]*?")
nil))
(should
(equal (xr-lint "a+?a?,a?a+?,a+?a*,a*a+?,a*?a?,a?a*?,a*?a*,a*a*?")
'(((39 40 "Repetition subsumes preceding repetition" warning)
(36 38 "Subsumed repetition here" info))
((44 46 "Repetition subsumed by preceding repetition" warning)
(42 43 "Subsuming repetition here" info)))))
(should
(equal (xr-lint "[ab]+?a??,a??[ab]+?,[ab]+?a*?,a*?[ab]+?")
'(((6 8 "Repetition subsumed by preceding repetition" warning)
(0 5 "Subsuming repetition here" info))
((13 18 "Repetition subsumes preceding repetition" warning)
(10 12 "Subsumed repetition here" info))
((26 28 "Repetition subsumed by preceding repetition" warning)
(20 25 "Subsuming repetition here" info))
((33 38"Repetition subsumes preceding repetition" warning)
(30 32 "Subsumed repetition here" info)))))
(should
(equal (xr-lint "[ab]*?a??,a??[ab]*?,[ab]*?a*?,a*?[ab]*?")
'(((6 8 "Repetition subsumed by preceding repetition" warning)
(0 5 "Subsuming repetition here" info))
((13 18 "Repetition subsumes preceding repetition" warning)
(10 12 "Subsumed repetition here" info))
((26 28 "Repetition subsumed by preceding repetition" warning)
(20 25 "Subsuming repetition here" info))
((33 38 "Repetition subsumes preceding repetition" warning)
(30 32 "Subsumed repetition here" info)))))
(should
(equal (xr-lint "a+?a??,a??a+?,a+?a*?,a*?a+?,a*?a??,a??a*?,a*?a*?")
'(((3 5 "Repetition subsumed by preceding repetition" warning)
(0 2 "Subsuming repetition here" info))
((10 12 "Repetition subsumes preceding repetition" warning)
(7 9 "Subsumed repetition here" info))
((17 19 "Repetition subsumed by preceding repetition" warning)
(14 16 "Subsuming repetition here" info))
((24 26 "Repetition subsumes preceding repetition" warning)
(21 23 "Subsumed repetition here" info))
((31 33 "Repetition subsumed by preceding repetition" warning)
(28 30 "Subsuming repetition here" info))
((38 40 "Repetition subsumes preceding repetition" warning)
(35 37 "Subsumed repetition here" info))
((45 47 "Repetition subsumed by preceding repetition" warning)
(42 44 "Subsuming repetition here" info)))))
))
(ert-deftest xr-lint-wrapped-subsumption ()