aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDima Kogan2016-04-22 11:43:04 -0600
committerDima Kogan2016-04-22 20:47:26 -0600
commitab34aca3834c3485b9117b0750e87e090f79232c (patch)
treedfc203cbdfa576b125e394203710eeaa5f2576af
parentfcfa188aa48b24a3d171054fe2daf4d5c4bf7d2b (diff)
downloademacs-dima_regex_embedded_modifiers.tar.gz
emacs-dima_regex_embedded_modifiers.zip
regex: added tests for the case-fold embedded modifiersdima_regex_embedded_modifiers
* test/src/regex/regex-tests.el (regex-tests-case-fold): new ERT test to validate the case-fold modifier functionality
-rw-r--r--test/src/regex/regex-tests.el190
1 files changed, 189 insertions, 1 deletions
diff --git a/test/src/regex/regex-tests.el b/test/src/regex/regex-tests.el
index bacb702bdab..5882d5ecf67 100644
--- a/test/src/regex/regex-tests.el
+++ b/test/src/regex/regex-tests.el
@@ -583,10 +583,198 @@ differences in behavior.")
583 (error "Error parsing TESTS file line: '%s'" (buffer-string)))) 583 (error "Error parsing TESTS file line: '%s'" (buffer-string))))
584 failures)) 584 failures))
585 585
586(ert-deftest regex-tests () 586(ert-deftest regex-tests-glibc ()
587 "Tests of the regular expression engine. This evaluates the 587 "Tests of the regular expression engine. This evaluates the
588BOOST, PCRE, PTESTS and TESTS test cases from glibc." 588BOOST, PCRE, PTESTS and TESTS test cases from glibc."
589 (should-not (regex-tests-BOOST)) 589 (should-not (regex-tests-BOOST))
590 (should-not (regex-tests-PCRE)) 590 (should-not (regex-tests-PCRE))
591 (should-not (regex-tests-PTESTS)) 591 (should-not (regex-tests-PTESTS))
592 (should-not (regex-tests-TESTS))) 592 (should-not (regex-tests-TESTS)))
593
594(defun regex-tests--should-match (case-fold dir re str)
595 "Does the given RE match the STR? Returns boolean value.
596CASE-FOLD indicates whether a global case-fold-search should be
597enabled (acceptable values are 'no-case-fold and 'yes-case-fold).
598DIR indicates the direction of search (acceptable values are
599'forward and 'backward). "
600 (let ((case-fold-search
601 (cond ((eq case-fold 'no-case-fold) nil)
602 ((eq case-fold 'yes-case-fold) t)
603 (t (error (format "Unknown case-fold value: %s" case-fold))))))
604
605 (with-temp-buffer
606 (insert str)
607 (cond ((eq dir 'forward)
608 (progn (goto-char (point-min))
609 (re-search-forward re nil t)))
610 ((eq dir 'backward)
611 (progn (goto-char (point-max))
612 (re-search-backward re nil t)))
613 (t (error (format "Unknown dir value: %s" dir)))))))
614
615(defun regex-tests--check-match (case-fold re str should-match &rest should-begend)
616 "Checks to make sure a regex match did/did not match as it was
617supposed to, and that all the start/end points were correct.
618These bounds are given in SHOULD-BEGEND, and are 1-based. "
619
620 (dolist (dir (list 'forward 'backward))
621 (if should-match
622 (should (regex-tests--should-match case-fold dir re str))
623 (should-not (regex-tests--should-match case-fold dir re str)))
624
625 (let ((idx 0))
626 (while should-begend
627 (should (= (match-beginning idx) (car should-begend)))
628 (should (= (match-end idx) (cadr should-begend)))
629
630 (setq should-begend (cddr should-begend)
631 idx (1+ idx))))))
632
633(defun regex-tests-should-match (case-fold re str &rest should-begend)
634 "Checks to make sure a regex match did match, and that all the
635start/end points were correct. These bounds are given in
636SHOULD-BEGEND, and are 1-based. "
637 (apply 'regex-tests--check-match case-fold re str t should-begend))
638
639(defun regex-tests-should-not-match (case-fold re str)
640 "Checks to make sure a regex match did not match."
641 (funcall 'regex-tests--check-match case-fold re str nil))
642
643
644
645(ert-deftest regex-tests-case-fold ()
646 "Tests of the case-fold embedded modifier."
647
648 (let ((str "abcABC"))
649 (regex-tests-should-match 'no-case-fold "\\(?i\\)Bc" str 2 4)
650 (regex-tests-should-match 'no-case-fold "\\(?i\\)bC" str 2 4)
651 (regex-tests-should-match 'yes-case-fold "\\(?i\\)Bc" str 2 4)
652 (regex-tests-should-match 'yes-case-fold "\\(?i\\)bC" str 2 4)
653 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)Bc" str)
654 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)bC" str)
655 (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)Bc" str)
656 (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)bC" str)
657 (regex-tests-should-match 'no-case-fold "B\\(?i\\)c" str 5 7)
658 (regex-tests-should-match 'no-case-fold "b\\(?i\\)C" str 2 4)
659 (regex-tests-should-match 'yes-case-fold "B\\(?i\\)c" str 2 4)
660 (regex-tests-should-match 'yes-case-fold "b\\(?i\\)C" str 2 4)
661 (regex-tests-should-not-match 'no-case-fold "B\\(?-i\\)c" str)
662 (regex-tests-should-not-match 'no-case-fold "b\\(?-i\\)C" str)
663 (regex-tests-should-match 'yes-case-fold "B\\(?-i\\)c" str 2 4)
664 (regex-tests-should-match 'yes-case-fold "b\\(?-i\\)C" str 5 7)
665
666 (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|\\(?i\\)Bc" str 2 4)
667 (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|\\(?i\\)bC" str 2 4)
668 (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|\\(?i\\)Bc" str 2 4)
669 (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|\\(?i\\)bC" str 2 4)
670 (regex-tests-should-not-match 'no-case-fold "\\(?i\\)x\\|\\(?-i\\)Bc" str)
671 (regex-tests-should-not-match 'no-case-fold "\\(?i\\)x\\|\\(?-i\\)bC" str)
672 (regex-tests-should-not-match 'yes-case-fold "\\(?i\\)x\\|\\(?-i\\)Bc" str)
673 (regex-tests-should-not-match 'yes-case-fold "\\(?i\\)x\\|\\(?-i\\)bC" str)
674 (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|B\\(?i\\)c" str 2 4)
675 (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|b\\(?i\\)C" str 2 4)
676 (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|B\\(?i\\)c" str 2 4)
677 (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|b\\(?i\\)C" str 2 4)
678 (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|B\\(?-i\\)c" str 2 4)
679 (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|b\\(?-i\\)C" str 5 7)
680 (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|B\\(?-i\\)c" str 2 4)
681 (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|b\\(?-i\\)C" str 5 7)
682
683
684 (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)C" str 5 7 5 6)
685 (regex-tests-should-not-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)B" str)
686 (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)c" str 2 4 2 3)
687 (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)b" str 1 3 1 2)
688 (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)C" str 2 4 2 3)
689 (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)B" str 1 3 1 2)
690 (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)c" str 2 4 2 3)
691 (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)b" str 1 3 1 2))
692
693
694
695 (let ((str "ABCabc"))
696 (regex-tests-should-match 'no-case-fold "\\(?i\\)Bc" str 2 4)
697 (regex-tests-should-match 'no-case-fold "\\(?i\\)bC" str 2 4)
698 (regex-tests-should-match 'yes-case-fold "\\(?i\\)Bc" str 2 4)
699 (regex-tests-should-match 'yes-case-fold "\\(?i\\)bC" str 2 4)
700 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)Bc" str)
701 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)bC" str)
702 (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)Bc" str)
703 (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)bC" str)
704 (regex-tests-should-match 'no-case-fold "B\\(?i\\)c" str 2 4)
705 (regex-tests-should-match 'no-case-fold "b\\(?i\\)C" str 5 7)
706 (regex-tests-should-match 'yes-case-fold "B\\(?i\\)c" str 2 4)
707 (regex-tests-should-match 'yes-case-fold "b\\(?i\\)C" str 2 4)
708 (regex-tests-should-not-match 'no-case-fold "B\\(?-i\\)c" str)
709 (regex-tests-should-not-match 'no-case-fold "b\\(?-i\\)C" str)
710 (regex-tests-should-match 'yes-case-fold "B\\(?-i\\)c" str 5 7)
711 (regex-tests-should-match 'yes-case-fold "b\\(?-i\\)C" str 2 4))
712
713 (let ((str "12abcdef"))
714 (regex-tests-should-match 'no-case-fold "abc" str 3 6)
715 (regex-tests-should-not-match 'no-case-fold "aBc" str)
716 (regex-tests-should-not-match 'no-case-fold "a\\(?-i\\)Bc" str)
717 (regex-tests-should-match 'no-case-fold "a\\(?i\\)B\\(?-i\\)c" str 3 6)
718 (regex-tests-should-not-match 'no-case-fold "a\\(?i\\)B\\(?-i\\)C" str)
719 (regex-tests-should-match 'no-case-fold "a\\(?:\\(?i\\)B\\)c" str 3 6)
720 (regex-tests-should-not-match 'no-case-fold "a\\(?:\\(?i\\)B\\)C" str)
721 (regex-tests-should-match 'no-case-fold "a\\(\\(?i\\)B\\)c" str 3 6 4 5)
722 (regex-tests-should-not-match 'no-case-fold "a\\(\\(?i\\)B\\)C" str)
723
724 (regex-tests-should-not-match 'no-case-fold "A\\(?:\\(?i\\)B\\)c" str)
725 (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?i\\)B\\)C" str 3 6)
726 (regex-tests-should-not-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)B\\)C" str)
727 (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)b\\)C" str 3 6)
728 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)A\\(?:\\(?i\\)B\\)C" str)
729 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)B\\)C" str)
730 (regex-tests-should-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)B\\)c" str 3 6)
731
732 (regex-tests-should-not-match 'no-case-fold "A\\(?:\\(?i\\)[B-B]\\)c" str)
733 (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?i\\)[B-B]\\)C" str 3 6)
734 (regex-tests-should-not-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)[B-B]\\)C" str)
735 (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)[b-b]\\)C" str 3 6)
736 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)A\\(?:\\(?i\\)[B-B]\\)C" str)
737 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)[B-B]\\)C" str)
738 (regex-tests-should-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)[B-B]\\)c" str 3 6)
739
740 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)C" str)
741 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)c" str 4 6)
742 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)c" str 4 6 4 5))
743
744 (let ((str "12axxxabcdef"))
745 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)C" str)
746 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)c" str 8 10)
747 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)c" str 8 10 8 9))
748
749 (let ((str "12aBcxxxABCabcdef"))
750
751 ;; These required changes in analyze_first() and re_search_2() to
752 ;; track case-fold inside fastmap[]
753 (regex-tests-should-match 'no-case-fold "\\(?i\\)B\\(?-i\\)C" str 10 12)
754 (regex-tests-should-match 'yes-case-fold "B\\(?-i\\)C" str 10 12)
755
756 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)C" str 10 12 10 11)
757 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)c" str 4 6 4 5)
758 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?-i\\)b\\)C" str)
759 (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)C" str 10 12 10 11)
760 (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)c" str 4 6 4 5)
761 (regex-tests-should-not-match 'no-case-fold "\\(\\(?-i\\)b\\)C" str)
762
763 (regex-tests-should-match 'no-case-fold "\\(?i\\)[B-B]\\(?-i\\)C" str 10 12)
764 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[B-B]\\)C" str 10 12 10 11)
765 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[B-B]\\)c" str 4 6 4 5)
766 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?-i\\)[b-b]\\)C" str)
767
768 (regex-tests-should-not-match 'no-case-fold "\\(?i\\)[^B-B]\\(?-i\\)C" str)
769 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[^B-B]\\)C" str)
770 (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[^B-B]\\)c" str)
771 (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?-i\\)[^b-b]\\)C" str 10 12 10 11)
772
773 (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)C" str 10 12 10 11)
774 (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)c" str 4 6 4 5))
775
776 (let ((str "abc"))
777 (regex-tests-should-match 'no-case-fold "^\\(?i\\)abc" str 1 4)
778 (regex-tests-should-match 'no-case-fold "\\(?i\\)^abc" str 1 4)
779 (regex-tests-should-match 'no-case-fold "abc\\(?i\\)$" str 1 4)
780 (regex-tests-should-match 'no-case-fold "abc$\\(?i\\)" str 1 4)))