diff options
author | Dima Kogan <dima@secretsauce.net> | 2016-04-22 11:43:04 -0600 |
---|---|---|
committer | Dima Kogan <dima@secretsauce.net> | 2016-04-22 20:47:26 -0600 |
commit | ab34aca3834c3485b9117b0750e87e090f79232c (patch) | |
tree | dfc203cbdfa576b125e394203710eeaa5f2576af | |
parent | fcfa188aa48b24a3d171054fe2daf4d5c4bf7d2b (diff) | |
download | emacs-dima_regex_embedded_modifiers.tar.gz |
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.el | 190 |
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.") (error "Error parsing TESTS file line: '%s'" (buffer-string)))) failures)) -(ert-deftest regex-tests () +(ert-deftest regex-tests-glibc () "Tests of the regular expression engine. This evaluates the BOOST, PCRE, PTESTS and TESTS test cases from glibc." (should-not (regex-tests-BOOST)) (should-not (regex-tests-PCRE)) (should-not (regex-tests-PTESTS)) (should-not (regex-tests-TESTS))) + +(defun regex-tests--should-match (case-fold dir re str) + "Does the given RE match the STR? Returns boolean value. +CASE-FOLD indicates whether a global case-fold-search should be +enabled (acceptable values are 'no-case-fold and 'yes-case-fold). +DIR indicates the direction of search (acceptable values are +'forward and 'backward). " + (let ((case-fold-search + (cond ((eq case-fold 'no-case-fold) nil) + ((eq case-fold 'yes-case-fold) t) + (t (error (format "Unknown case-fold value: %s" case-fold)))))) + + (with-temp-buffer + (insert str) + (cond ((eq dir 'forward) + (progn (goto-char (point-min)) + (re-search-forward re nil t))) + ((eq dir 'backward) + (progn (goto-char (point-max)) + (re-search-backward re nil t))) + (t (error (format "Unknown dir value: %s" dir))))))) + +(defun regex-tests--check-match (case-fold re str should-match &rest should-begend) + "Checks to make sure a regex match did/did not match as it was +supposed to, and that all the start/end points were correct. +These bounds are given in SHOULD-BEGEND, and are 1-based. " + + (dolist (dir (list 'forward 'backward)) + (if should-match + (should (regex-tests--should-match case-fold dir re str)) + (should-not (regex-tests--should-match case-fold dir re str))) + + (let ((idx 0)) + (while should-begend + (should (= (match-beginning idx) (car should-begend))) + (should (= (match-end idx) (cadr should-begend))) + + (setq should-begend (cddr should-begend) + idx (1+ idx)))))) + +(defun regex-tests-should-match (case-fold re str &rest should-begend) + "Checks to make sure a regex match did match, and that all the +start/end points were correct. These bounds are given in +SHOULD-BEGEND, and are 1-based. " + (apply 'regex-tests--check-match case-fold re str t should-begend)) + +(defun regex-tests-should-not-match (case-fold re str) + "Checks to make sure a regex match did not match." + (funcall 'regex-tests--check-match case-fold re str nil)) + + + +(ert-deftest regex-tests-case-fold () + "Tests of the case-fold embedded modifier." + + (let ((str "abcABC")) + (regex-tests-should-match 'no-case-fold "\\(?i\\)Bc" str 2 4) + (regex-tests-should-match 'no-case-fold "\\(?i\\)bC" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)Bc" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)bC" str 2 4) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)Bc" str) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)bC" str) + (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)Bc" str) + (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)bC" str) + (regex-tests-should-match 'no-case-fold "B\\(?i\\)c" str 5 7) + (regex-tests-should-match 'no-case-fold "b\\(?i\\)C" str 2 4) + (regex-tests-should-match 'yes-case-fold "B\\(?i\\)c" str 2 4) + (regex-tests-should-match 'yes-case-fold "b\\(?i\\)C" str 2 4) + (regex-tests-should-not-match 'no-case-fold "B\\(?-i\\)c" str) + (regex-tests-should-not-match 'no-case-fold "b\\(?-i\\)C" str) + (regex-tests-should-match 'yes-case-fold "B\\(?-i\\)c" str 2 4) + (regex-tests-should-match 'yes-case-fold "b\\(?-i\\)C" str 5 7) + + (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|\\(?i\\)Bc" str 2 4) + (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|\\(?i\\)bC" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|\\(?i\\)Bc" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|\\(?i\\)bC" str 2 4) + (regex-tests-should-not-match 'no-case-fold "\\(?i\\)x\\|\\(?-i\\)Bc" str) + (regex-tests-should-not-match 'no-case-fold "\\(?i\\)x\\|\\(?-i\\)bC" str) + (regex-tests-should-not-match 'yes-case-fold "\\(?i\\)x\\|\\(?-i\\)Bc" str) + (regex-tests-should-not-match 'yes-case-fold "\\(?i\\)x\\|\\(?-i\\)bC" str) + (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|B\\(?i\\)c" str 2 4) + (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|b\\(?i\\)C" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|B\\(?i\\)c" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|b\\(?i\\)C" str 2 4) + (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|B\\(?-i\\)c" str 2 4) + (regex-tests-should-match 'no-case-fold "\\(?i\\)x\\|b\\(?-i\\)C" str 5 7) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|B\\(?-i\\)c" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)x\\|b\\(?-i\\)C" str 5 7) + + + (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)C" str 5 7 5 6) + (regex-tests-should-not-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)B" str) + (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)c" str 2 4 2 3) + (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)b" str 1 3 1 2) + (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)C" str 2 4 2 3) + (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)B" str 1 3 1 2) + (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)c" str 2 4 2 3) + (regex-tests-should-match 'yes-case-fold "\\(\\(?i\\)x\\|\\(?-i\\)a\\|\\(?i\\)B\\)b" str 1 3 1 2)) + + + + (let ((str "ABCabc")) + (regex-tests-should-match 'no-case-fold "\\(?i\\)Bc" str 2 4) + (regex-tests-should-match 'no-case-fold "\\(?i\\)bC" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)Bc" str 2 4) + (regex-tests-should-match 'yes-case-fold "\\(?i\\)bC" str 2 4) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)Bc" str) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)bC" str) + (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)Bc" str) + (regex-tests-should-not-match 'yes-case-fold "\\(?-i\\)bC" str) + (regex-tests-should-match 'no-case-fold "B\\(?i\\)c" str 2 4) + (regex-tests-should-match 'no-case-fold "b\\(?i\\)C" str 5 7) + (regex-tests-should-match 'yes-case-fold "B\\(?i\\)c" str 2 4) + (regex-tests-should-match 'yes-case-fold "b\\(?i\\)C" str 2 4) + (regex-tests-should-not-match 'no-case-fold "B\\(?-i\\)c" str) + (regex-tests-should-not-match 'no-case-fold "b\\(?-i\\)C" str) + (regex-tests-should-match 'yes-case-fold "B\\(?-i\\)c" str 5 7) + (regex-tests-should-match 'yes-case-fold "b\\(?-i\\)C" str 2 4)) + + (let ((str "12abcdef")) + (regex-tests-should-match 'no-case-fold "abc" str 3 6) + (regex-tests-should-not-match 'no-case-fold "aBc" str) + (regex-tests-should-not-match 'no-case-fold "a\\(?-i\\)Bc" str) + (regex-tests-should-match 'no-case-fold "a\\(?i\\)B\\(?-i\\)c" str 3 6) + (regex-tests-should-not-match 'no-case-fold "a\\(?i\\)B\\(?-i\\)C" str) + (regex-tests-should-match 'no-case-fold "a\\(?:\\(?i\\)B\\)c" str 3 6) + (regex-tests-should-not-match 'no-case-fold "a\\(?:\\(?i\\)B\\)C" str) + (regex-tests-should-match 'no-case-fold "a\\(\\(?i\\)B\\)c" str 3 6 4 5) + (regex-tests-should-not-match 'no-case-fold "a\\(\\(?i\\)B\\)C" str) + + (regex-tests-should-not-match 'no-case-fold "A\\(?:\\(?i\\)B\\)c" str) + (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?i\\)B\\)C" str 3 6) + (regex-tests-should-not-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)B\\)C" str) + (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)b\\)C" str 3 6) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)A\\(?:\\(?i\\)B\\)C" str) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)B\\)C" str) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)B\\)c" str 3 6) + + (regex-tests-should-not-match 'no-case-fold "A\\(?:\\(?i\\)[B-B]\\)c" str) + (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?i\\)[B-B]\\)C" str 3 6) + (regex-tests-should-not-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)[B-B]\\)C" str) + (regex-tests-should-match 'no-case-fold "\\(?i\\)A\\(?:\\(?-i\\)[b-b]\\)C" str 3 6) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)A\\(?:\\(?i\\)[B-B]\\)C" str) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)[B-B]\\)C" str) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)a\\(?:\\(?i\\)[B-B]\\)c" str 3 6) + + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)C" str) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)c" str 4 6) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)c" str 4 6 4 5)) + + (let ((str "12axxxabcdef")) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)C" str) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(?:\\(?i\\)B\\)c" str 8 10) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)c" str 8 10 8 9)) + + (let ((str "12aBcxxxABCabcdef")) + + ;; These required changes in analyze_first() and re_search_2() to + ;; track case-fold inside fastmap[] + (regex-tests-should-match 'no-case-fold "\\(?i\\)B\\(?-i\\)C" str 10 12) + (regex-tests-should-match 'yes-case-fold "B\\(?-i\\)C" str 10 12) + + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)C" str 10 12 10 11) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)B\\)c" str 4 6 4 5) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?-i\\)b\\)C" str) + (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)C" str 10 12 10 11) + (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)c" str 4 6 4 5) + (regex-tests-should-not-match 'no-case-fold "\\(\\(?-i\\)b\\)C" str) + + (regex-tests-should-match 'no-case-fold "\\(?i\\)[B-B]\\(?-i\\)C" str 10 12) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[B-B]\\)C" str 10 12 10 11) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[B-B]\\)c" str 4 6 4 5) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?-i\\)[b-b]\\)C" str) + + (regex-tests-should-not-match 'no-case-fold "\\(?i\\)[^B-B]\\(?-i\\)C" str) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[^B-B]\\)C" str) + (regex-tests-should-not-match 'no-case-fold "\\(?-i\\)\\(\\(?i\\)[^B-B]\\)c" str) + (regex-tests-should-match 'no-case-fold "\\(?-i\\)\\(\\(?-i\\)[^b-b]\\)C" str 10 12 10 11) + + (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)C" str 10 12 10 11) + (regex-tests-should-match 'no-case-fold "\\(\\(?i\\)B\\)c" str 4 6 4 5)) + + (let ((str "abc")) + (regex-tests-should-match 'no-case-fold "^\\(?i\\)abc" str 1 4) + (regex-tests-should-match 'no-case-fold "\\(?i\\)^abc" str 1 4) + (regex-tests-should-match 'no-case-fold "abc\\(?i\\)$" str 1 4) + (regex-tests-should-match 'no-case-fold "abc$\\(?i\\)" str 1 4))) |